Skip to content

Harden PBM RLE short reads and no-op termination - #162

Merged
danoli3 merged 1 commit into
masterfrom
fix/iff-pbm-short-reads
Oct 14, 2026
Merged

danoli3 merged 1 commit into
masterfrom
fix/iff-pbm-short-reads

Conversation

@danoli3

@danoli3 danoli3 commented Oct 14, 2026

Copy link
Copy Markdown
Owner

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:

  • Ubuntu 24.04 ARM64 container, GCC/G++ 13.3, existing CMake build with bundled codecs and -fsanitize=address -g on both C and C++, plus ASan executable linking.
  • Pre-fix baseline e1105d3 (the fix heap overflow in IFF PBM RLE decompression #161 merge): noops, row-noops and noops-eof each timed out after two seconds. Both valid-image cases passed before the fix.
  • Fixed build: all ten malformed cases reject cleanly, both valid images retain identical pixels, and MainTestSuite, IffPbmRleTest and VendorCodecTest all pass with zero ASan reports.
  • No warnings from the changed decoder or new regression test. Cross-platform GitHub CI runs after this PR opens.

@danoli3
danoli3 merged commit cf173c1 into master Oct 14, 2026
41 checks 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.

1 participant