Fix: Buffer.from() in CRC helpers prevents browser/Deno/Bun execution#444
Fix: Buffer.from() in CRC helpers prevents browser/Deno/Bun execution#444kevinelliott wants to merge 1 commit into
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR replaces Node.js ChangesCRC-16 Runtime Compatibility
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ciinitially fails on the repo’s current@typescript-eslintpeer dependency conflict, so I installed withnpm ci --legacy-peer-deps.npm test -- Label_H1 --runInBandpassed: 23 suites, 115 tests, 2 skipped.npm run buildpassed.npm test -- --runInBandpassed: 88 suites, 407 tests, 9 skipped.npx eslint lib/utils/arinc_702_helper.tshad no errors; it only reports an existing unrelated unuseddatewarning.
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.
Sent by Cursor Automation: acars-decoder-typescript: PR Review


Summary
Buffer.from(data, 'ascii')calls inlib/utils/arinc_702_helper.ts(in the CRC-16 IBM SDLC and GENIBUS checksum helpers) were missed by the Web APIs migration in c78b720.ReferenceError: Buffer is not definedwhenever ARINC 702 H1 checksum validation runs in a non-Node environment (browser, Deno, Bun, edge runtimes — exactly the runtimes the migration targeted).asciiStringToBytes()helper. Byte values are identical toBuffer.from(s, 'ascii'): one byte per char, masked with0xff.How it was found
Surfaced while moving
lib/utils/intoairframes-decoder/runtimes/typescript/for the cross-language unification work. The runtime package's stricter tsconfig flagged theBufferreference that the looser project tsconfig allows through.Test plan
npm test -- --testPathPatterns='Label_H1'— 23 suites, 115 tests pass, 2 skipped (matches baseline)Risk
🤖 Generated with Claude Code
Summary by CodeRabbit