Skip to content

Fix Zlib::Inflate#sync with input over UINT_MAX bytes - #169

Merged
hsbt merged 1 commit into
masterfrom
claude/inflate-sync-uint-max-1f270d
Oct 26, 2026
Merged

hsbt merged 1 commit into
masterfrom
claude/inflate-sync-uint-max-1f270d

Conversation

@hsbt

@hsbt hsbt commented Oct 25, 2026

Copy link
Copy Markdown
Member

Zlib::Inflate#sync gave inflateSync only the first UINT_MAX bytes of a longer input, but consumed the input as if all of it had been searched. The data after the sync point was lost, and a sync point past those bytes was never found.

  d = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS)
  src = "\0" * (2**32 - 5) + "\0\0\xFF\xFF".b + d.deflate("hello", Zlib::FINISH)
  z = Zlib::Inflate.new
  z.sync(src)   #=> true
  z.inflate("") #=> "" (expected "hello")

I didn't add a test because it needs a String over 4 GiB. I checked the snippet and the same cases with the data already buffered in the stream on x86_64-linux.

Generated with Claude Code

inflateSync was given only the first UINT_MAX bytes, but the input was consumed as if all of it had been searched, so the data after the sync point was lost and a sync point past those bytes was never found.

  d = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS)
  src = "\0" * (2**32 - 5) + "\0\0\xFF\xFF".b + d.deflate("hello", Zlib::FINISH)
  z = Zlib::Inflate.new
  z.sync(src)   #=> true
  z.inflate("") #=> "" (expected "hello")

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hsbt
hsbt merged commit 22aeed0 into master Oct 26, 2026
60 checks passed
@hsbt
hsbt deleted the claude/inflate-sync-uint-max-1f270d branch October 26, 2026 04:32
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