Skip to content

Reject invalid DEFLATE HLIT values - #67

Merged
Coralesoft merged 1 commit into
mainfrom
fix/inflate-hlit-bounds
Aug 4, 2026
Merged

Reject invalid DEFLATE HLIT values#67
Coralesoft merged 1 commit into
mainfrom
fix/inflate-hlit-bounds

Conversation

@Coralesoft

Copy link
Copy Markdown
Collaborator

Inflator::DecodeHeader() accepted HLIT values 30 and 31, although RFC 1951 limits HLIT to 0 through 29.

With the maximum HDIST value, the calculated fill length could reach 320 entries against the 318-entry code-length table. The existing guard compared against that same malformed bound rather than the table capacity, allowing an out-of-bounds write. On the layouts tested, this clears the m_allocated flag in the SecBlock allocator and triggers CRYPTOPP_ASSERT(m_allocated) during destruction.

Reported upstream as weidai11/cryptopp#1368.

HDIST values 30 and 31 remain accepted. RFC 1951 permits the full 0 through 31 range, and CreateFixedDistanceDecoder() initialises all 32 distance codes. Only HLIT is out of range; 286 literal/length codes plus 32 distance codes gives the correct table size of 318.

What changed:

  • Reject hlit > 29 before filling the code-length table.
  • Calculate the literal, distance, and total counts once.
  • Check repeat runs against both the declared alphabet size and the table capacity.

RFC 1951 limits HLIT to values 0 through 29. Reject 30 and 31 before filling the dynamic code-length table, and check repeat runs against both the declared alphabet size and table capacity.

Refs: weidai11/cryptopp#1368
@Coralesoft
Coralesoft merged commit b80f7f1 into main Aug 4, 2026
47 checks passed
@Coralesoft
Coralesoft deleted the fix/inflate-hlit-bounds branch August 4, 2026 08:47
@Coralesoft Coralesoft mentioned this pull request Aug 5, 2026
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