Skip to content

Validate BZip2InputStream header and decoding table bounds - #906

Open
seragAhmed wants to merge 1 commit into
icsharpcode:masterfrom
seragAhmed:fix/904-bzip2-bounds-checks
Open

seragAhmed wants to merge 1 commit into
icsharpcode:masterfrom
seragAhmed:fix/904-bzip2-bounds-checks

Conversation

@seragAhmed

Copy link
Copy Markdown

Adds bounds validation in BZip2InputStream so malformed bzip2 streams throw BZip2Exception instead of IndexOutOfRangeException or NullReferenceException:

  • Reject invalid headers (BZh[1-9]) in Initialize() instead of leaving tt/ll8 null and continuing into InitBlock()/SetupBlock().
  • Validate nInUse, nGroups, nSelectors, selector MTF indices, and Huffman code lengths (1..20) in RecvDecodingTables() and HbCreateDecodeTables().
  • Bounds-check groupNo, Huffman code length, permutation index, and RLE expansion length before indexing arrays in GetAndMoveToFrontDecode().
  • Validate origPtr and guard against streamEnd in SetupBlock().
  • Add regression tests covering the five malformed inputs from the issue.

Fixes #904.

@icsharpcode icsharpcode deleted a comment from SourceproStudio Nov 24, 2026

This branch has not been deployed

No deployments
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.

BZip2InputStream: multiple crashes from malformed input

2 participants