Repository navigation
Harden PBM RLE short reads and no-op termination - #162
Merged
Merged
Conversation
This was referenced Oct 14, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IFF PBM RLE decoding can spin indefinitely when a truncated stream leaves command byte 128 (ByteRun1's no-op) as its stale value. Unchecked command, literal-byte and repeat-value reads can also decode stale stack data after EOF.
This follow-up uses a checked byte reader and a byte budget for the declared BODY chunk. Every command, including a no-op, consumes that budget. If a read fails or the BODY ends before a row is complete, the loader unloads the partial bitmap and returns NULL. The PBM write bounds added by #161 remain intact; the ILBM path and uncompressed PBM reads are unchanged.
These are robustness and denial-of-service hardening issues distinct from the heap overflow reported in #156 and fixed by #161. The parentheses added in #161 are cosmetic:
+already binds tighter than&in C/C++. This PR leaves that line calculation unchanged.Add a CMake regression executable covering ten malformed cases (short reads at each read site, EOF after no-ops, no-ops left after a clipped literal packet, and BODY boundary enforcement) and two valid literal/repeat images checked byte-for-byte. Give the test a five-second CTest timeout and run it in the existing GCC ASan CI jobs with OpenJPH SIMD on and off, as well as the normal test matrix.
Validation:
-fsanitize=address -gon both C and C++, plus ASan executable linking.e1105d3(the fix heap overflow in IFF PBM RLE decompression #161 merge):noops,row-noopsandnoops-eofeach timed out after two seconds. Both valid-image cases passed before the fix.