Skip to content

Prevent infinite loop when array element consumes no bytes - #319

Open
keichi wants to merge 1 commit into
masterfrom
fix-array-infinite-loop
Open

keichi wants to merge 1 commit into
masterfrom
fix-array-infinite-loop

Conversation

@keichi

@keichi keichi commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Problem: arrays with readUntil: "eof" or lengthInBytes loop until offset reaches the end. If an element consumes 0 bytes (e.g. the element is only a pointer, or a seek driven by input data), offset never advances and the loop runs forever while the array grows until OOM.

Repro (hangs):

new Parser()
  .array("a", { type: new Parser().pointer("p", { offset: 0, type: "uint8" }), readUntil: "eof" })
  .parse(Buffer.from([1]));

Fix: for these two loop forms, record offset at the start of each iteration and throw Array element did not consume any bytes if it did not advance. Fixed-length and readUntil-function arrays are unchanged. Added a regression test covering both forms.

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.

1 participant