Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/operations/ParseIPv4Header.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ParseIPv4Header extends Operation {
checksum = input[10] << 8 | input[11],
srcIP = input[12] << 24 | input[13] << 16 | input[14] << 8 | input[15],
dstIP = input[16] << 24 | input[17] << 16 | input[18] << 8 | input[19],
checksumHeader = input.slice(0, 10).concat([0, 0]).concat(input.slice(12, 20));
checksumHeader = [...input.slice(0, 10), 0, 0, ...input.slice(12, 20)];
let version = (input[0] >>> 4) & 0x0f,
options = [];

Expand Down
1 change: 1 addition & 0 deletions tests/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import TestRegister from "../lib/TestRegister.mjs";
import "./tests/nodeApi.mjs";
import "./tests/operations.mjs";
import "./tests/ParseIPv4Header.mjs";
import "./tests/File.mjs";
import "./tests/Dish.mjs";
import "./tests/NodeDish.mjs";
Expand Down
25 changes: 25 additions & 0 deletions tests/node/tests/ParseIPv4Header.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import assert from "assert";
import it from "../assertionHandler.mjs";
import TestRegister from "../../lib/TestRegister.mjs";
import ParseIPv4Header from "../../../src/core/operations/ParseIPv4Header.mjs";

TestRegister.addApiTests([
it("Parse IPv4 header: regression for Uint8Array.concat crash on truncated raw input", () => {
const operation = new ParseIPv4Header();
const truncatedHeader = new Uint8Array([0x45, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0x00]);
// The Raw path converts the input into a Uint8Array before checksum header construction.
const rawInput = String.fromCharCode(...truncatedHeader);
let result;
let thrownError;

try {
result = operation.run(rawInput, ["Raw", "Data (raw)"]);
} catch (err) {
thrownError = err;
}

assert.ok(!(thrownError instanceof TypeError), `Unexpected TypeError: ${thrownError && thrownError.message}`);
assert.ifError(thrownError);
assert.strictEqual(typeof result, "string");
})
]);