Skip to content

Fix Uint8Array concat crash in Parse IPv4 header#2409

Open
Zish19 wants to merge 1 commit into
gchq:masterfrom
Zish19:fix-ipv4-uint8array-concat
Open

Fix Uint8Array concat crash in Parse IPv4 header#2409
Zish19 wants to merge 1 commit into
gchq:masterfrom
Zish19:fix-ipv4-uint8array-concat

Conversation

@Zish19
Copy link
Copy Markdown

@Zish19 Zish19 commented May 18, 2026

Fixes #2400

Summary

Fixes a runtime TypeError in the Parse IPv4 header operation caused by calling .concat() on a Uint8Array.

Root Cause

input.slice() returns a Uint8Array, not a standard JavaScript Array.

The operation previously attempted to do:

input.slice(0, 10).concat([0, 0]).concat(input.slice(12, 20));

Since Uint8Array does not implement .concat(), malformed/raw input caused:

TypeError: e.slice(...).concat is not a function

This affects both:

  • Raw input mode
  • Hex input mode (fromHex() also returns Uint8Array)

Fix

Replaced the unsafe concatenation with array spreading:

[...input.slice(0, 10), 0, 0, ...input.slice(12, 20)]

This preserves the exact byte sequence while producing a standard array compatible with the downstream checksum logic.

Notes

  • Minimal isolated fix
  • No unrelated refactoring
  • No behavioral changes outside checksum header construction
  • Prevents crashes on malformed/truncated input
  • Valid IPv4 parsing behavior remains unchanged

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 18, 2026

CLA assistant check
All committers have signed the CLA.

@Zish19 Zish19 force-pushed the fix-ipv4-uint8array-concat branch from e827a28 to 1c5fafd Compare May 18, 2026 20:03
@Zish19
Copy link
Copy Markdown
Author

Zish19 commented May 18, 2026

CLA issue has been resolved and the branch has been updated successfully.
The fix remains minimal and isolated to the affected checksum header construction logic in ParseIPv4Header.mjs.
Please let me know if any additional changes, tests, or adjustments are needed.

Copy link
Copy Markdown
Contributor

@GCHQDeveloper581 GCHQDeveloper581 left a comment

Choose a reason for hiding this comment

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

Please add a test that would fail without this patch and pass with it present.

Please also provide an AI disclosure in the header of your PR stating if AI has been used in creation of the PR and if so what model(s) has(have) been used.

@Zish19
Copy link
Copy Markdown
Author

Zish19 commented May 20, 2026

Thanks for the review.

I’ll add a regression test covering the malformed/raw input case that previously triggered the Uint8Array.concat TypeError, and update the PR description with an AI usage disclosure.

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.

bug(parse ipv4 header): TypeError

3 participants