Skip to content

Stop readHexString at the end of its input - #91

Merged
ledongthuc merged 1 commit into
ledongthuc:masterfrom
stan-threatmate:fix-hex-string-eof
Oct 20, 2026
Merged

ledongthuc merged 1 commit into
ledongthuc:masterfrom
stan-threatmate:fix-hex-string-eof

Conversation

@stan-threatmate

@stan-threatmate stan-threatmate commented Sep 29, 2026 •

Copy link
Copy Markdown

A content stream that ends inside a hex string makes GetPlainText loop forever. At end of input readByte returns '\n', readHexString skips it as white space, and it never returns. It is the same shape #79 fixed for readArray.

Damaged files produce it: an uncompressed content stream whose /Length is shorter than its data, cut inside a <...> string. A compressed stream cut short fails with an error instead.

The fix stops the loop at end of input, as readArray and readDict do. The same two checks are part of #78's wider hardening, which conflicts with master today; this is that hex-string fix on its own, in the shape of #79. TestUnterminatedHexStringTerminates covers three cuts: between pairs of digits, inside a pair, and inside an array. Each case hangs past the test's 5 s bound without the fix. The test reuses the unterminated-array test's builder, which now takes the content as a parameter.

A content stream that ends inside a hex string, as one does when its
/Length is short, made readHexString loop for ever: at end of input
readByte returns '\n', and the loop skips it as white space. It now stops
at end of input, as readArray and readDict do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HwFWqvYkhLz3RSShWD1qxQ
@ledongthuc

Copy link
Copy Markdown
Owner

looks good

@ledongthuc
ledongthuc merged commit 5e46805 into ledongthuc:master Oct 20, 2026
1 check passed
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.

3 participants