Add ParseIPv4Header Uint8Array regression test

This commit is contained in:
Shivam 2026-05-23 12:07:08 +05:30
parent 6e1f05c9b8
commit 2f40f7130d
2 changed files with 26 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import {
import TestRegister from "../lib/TestRegister.mjs"; import TestRegister from "../lib/TestRegister.mjs";
import "./tests/nodeApi.mjs"; import "./tests/nodeApi.mjs";
import "./tests/operations.mjs"; import "./tests/operations.mjs";
import "./tests/ParseIPv4Header.mjs";
import "./tests/File.mjs"; import "./tests/File.mjs";
import "./tests/Dish.mjs"; import "./tests/Dish.mjs";
import "./tests/NodeDish.mjs"; import "./tests/NodeDish.mjs";

View File

@ -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");
})
]);