Skip to content

Keep Inflater's remaining count exact when the output buffer is small - #64

Merged
Project516 merged 1 commit into
masterfrom
p516/inflate-remaining
Nov 6, 2026
Merged

Project516 merged 1 commit into
masterfrom
p516/inflate-remaining

Conversation

@Project516

Copy link
Copy Markdown
Owner

What this changes

The faster inflate loop in #62 reads up to four input bytes ahead into its bit buffer. When a call stopped because the output was full, those bytes counted as read. At the end of the stream only bytes from the current call could be given back, so Inflater.getRemaining() came out short when the output buffer was small.

ZipInputStream uses that count to find the data descriptor after an entry, so reading a deflated entry through a small buffer then failed on the next entry with "invalid entry size". java/util/zip/GZIP/GZIPInZip.java hits it with a 4-byte GZIPInputStream buffer once the entries are really compressed.

Each call now gives back the whole bytes left in the bit buffer, as zlib does, so input is consumed exactly up to the end of the stream.

Tests

test/zip.test.ts inflates a stream followed by extra bytes with output buffers of 1 to 8 bytes and checks that exactly the stream is read. It fails without the fix. pnpm typecheck and test/zip.test.ts pass.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1f6363ff-6e20-4730-a2d7-54bbcf3916b9
Commits

Reviewing files that changed from the base of the PR and between 62c4b48 and 7fc2105.

Files selected for processing: 2

  • src/inflate.ts
  • test/zip.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix adjusts Inflate.run to return unconsumed whole bytes from the bit buffer on every call (not just at stream end), capping at the current call's consumed bytes. This matches zlib's behavior and keeps getRemaining exact when output buffers are small. The new test verifies exact stream consumption with output sizes 1–8 bytes.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 merged commit 170bcd5 into master Nov 6, 2026
16 checks passed
@Project516
Project516 deleted the p516/inflate-remaining branch November 6, 2026 21:37
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