Skip to content

Fix: Buffer.from() in CRC helpers prevents browser/Deno/Bun execution#444

Open
kevinelliott wants to merge 1 commit into
masterfrom
fix/h1-crc-buffer-web-apis
Open

Fix: Buffer.from() in CRC helpers prevents browser/Deno/Bun execution#444
kevinelliott wants to merge 1 commit into
masterfrom
fix/h1-crc-buffer-web-apis

Conversation

@kevinelliott
Copy link
Copy Markdown
Contributor

@kevinelliott kevinelliott commented May 28, 2026

Summary

  • Two surviving Buffer.from(data, 'ascii') calls in lib/utils/arinc_702_helper.ts (in the CRC-16 IBM SDLC and GENIBUS checksum helpers) were missed by the Web APIs migration in c78b720.
  • These would throw ReferenceError: Buffer is not defined whenever ARINC 702 H1 checksum validation runs in a non-Node environment (browser, Deno, Bun, edge runtimes — exactly the runtimes the migration targeted).
  • Replaces both calls with a small inline asciiStringToBytes() helper. Byte values are identical to Buffer.from(s, 'ascii'): one byte per char, masked with 0xff.

How it was found

Surfaced while moving lib/utils/ into airframes-decoder/runtimes/typescript/ for the cross-language unification work. The runtime package's stricter tsconfig flagged the Buffer reference that the looser project tsconfig allows through.

Test plan

  • npm test -- --testPathPatterns='Label_H1' — 23 suites, 115 tests pass, 2 skipped (matches baseline)
  • Manual verification in a browser context once merged (CI does not currently run browser tests)

Risk

  • Behavior-preserving. Same byte values, same loop, same CRC math. Only the byte-extraction primitive changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved runtime compatibility for CRC-16 checksum calculations, enabling proper functionality across browser, Deno, Bun, and edge computing environments.

Review Change Stack

The Web APIs migration in c78b720 removed all Node.js Buffer usage so the
decoder runs cleanly in browser, Deno, Bun, and edge runtimes — but two
calls in the CRC-16 helpers (crc16IbmSdlcRev and crc16Genibus) were
missed. Both still called `Buffer.from(data, 'ascii')`, which is
undefined outside Node and would throw `ReferenceError: Buffer is not
defined` when ARINC 702 H1 checksum validation runs in non-Node
environments.

Fix: replace with a small inline `asciiStringToBytes()` helper that
walks the string and writes one byte per char into a Uint8Array (exactly
what `Buffer.from(s, 'ascii')` does). Same per-char masking with 0xff so
the byte values are identical.

Surfaced while centralizing the lib/utils/ helpers into the
airframes-decoder repo's runtimes/typescript/ for the upcoming
cross-language unification work; the runtime package's stricter tsconfig
caught the surviving Buffer references that the original repo's looser
config did not.

Verified: 23 Label_H1 test suites green (115/117 tests pass, 2 skipped
matching baseline).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 28, 2026 05:12
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3c6427c1-ab12-4537-a17e-c943632635c8

📥 Commits

Reviewing files that changed from the base of the PR and between 1748860 and 93a2f2c.

📒 Files selected for processing (1)
  • lib/utils/arinc_702_helper.ts

Walkthrough

This PR replaces Node.js Buffer usage in CRC-16 checksum functions with a portable asciiStringToBytes() helper, enabling compatibility across browser, Deno, Bun, and edge runtime environments. The CRC calculation logic remains unchanged.

Changes

CRC-16 Runtime Compatibility

Layer / File(s) Summary
ASCII-to-bytes helper and CRC-16 updates
lib/utils/arinc_702_helper.ts
Introduces asciiStringToBytes() helper (lines 10–18) to convert ASCII strings to Uint8Array by mapping character code points to bytes, then updates crc16IbmSdlcRev (line 670) and crc16Genibus (line 701) to use this helper instead of Buffer.from(data, 'ascii').

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

enhancement

Suggested reviewers

  • makrsmark
  • daviesgeek

Poem

🐰 A buffer no more, just bytes in the air,
Across all the runtimes, CRC checksums fare!
From Node to Deno, the checksums ring true,
One helper to bind them, a portable breakthrough! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing Buffer.from() calls in CRC helpers to fix execution in non-Node environments (browser/Deno/Bun).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/h1-crc-buffer-web-apis

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the prior Web APIs migration for ARINC 702 CRC validation by removing remaining runtime Buffer usage from checksum helpers, improving compatibility with browser, Deno, Bun, and edge runtimes.

Changes:

  • Adds a module-local asciiStringToBytes() helper.
  • Replaces two Buffer.from(data, 'ascii') calls in CRC-16 helper functions with the new helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking findings. This is a good, narrowly scoped fix for the browser/Deno/Bun runtime failure.

The important detail here is that the replacement preserves the old Buffer.from(data, 'ascii') byte semantics: one byte per JavaScript string code unit, masked with 0xff. That matters for CRC validation because changing to TextEncoder would encode UTF-8 and could produce different bytes for non-ASCII input, which would change checksums. For ARINC/H1 data, the payloads are effectively ASCII, and this helper keeps the historical Node behavior while removing the Node-only global dependency.

I also confirmed that the built artifacts no longer contain Buffer references from this path.

Checks run:

  • npm ci initially fails on the repo’s current @typescript-eslint peer dependency conflict, so I installed with npm ci --legacy-peer-deps.
  • npm test -- Label_H1 --runInBand passed: 23 suites, 115 tests, 2 skipped.
  • npm run build passed.
  • npm test -- --runInBand passed: 88 suites, 407 tests, 9 skipped.
  • npx eslint lib/utils/arinc_702_helper.ts had no errors; it only reports an existing unrelated unused date warning.

Non-blocking suggestion for future hardening: consider adding a small regression test or smoke test that runs H1 checksum validation with globalThis.Buffer unavailable, or at least asserts the byte conversion matches legacy Buffer.from(..., 'ascii') for representative strings. That would make the runtime compatibility goal explicit and prevent a future refactor from accidentally switching these CRC inputs to UTF-8 bytes.

Open in Web View Automation 

Sent by Cursor Automation: acars-decoder-typescript: PR Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants