Repository navigation
Fix GzipReader#gets(limit) splitting a multibyte character at the buffer end - #178
Merged
hsbt merged 1 commit intoNov 26, 2026
Merged
Conversation
hsbt
force-pushed
the
segiddins/gzreader-gets-limit-charboundary
branch
from
November 26, 2026 08:15
a4bb4cd to
a3add6b
Compare
…fer end
gzreader_charboundary finds how many bytes of the character at the limit are missing from the inflated buffer, but asked gzfile_fill for only n + missing bytes. When the buffer already held more than n bytes nothing new was read, and the character was cut. The inflated buffer ends inside a character whenever a 2048-byte read of compressed data does.
```ruby
content = (("\u3042\u3044\u3046" * 700) + "\n") * 3
r = Zlib::GzipReader.new(StringIO.new(Zlib.gzip(content, level: 0)))
lines = []
while (line = r.gets(1)) do lines << line end
lines.reject(&:valid_encoding?).size
# expected: 0
# actual: 2
```
Request the buffer length plus the missing bytes instead.
Fixes ruby#92
Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
hsbt
force-pushed
the
segiddins/gzreader-gets-limit-charboundary
branch
from
November 26, 2026 09:49
a3add6b to
55682e6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gzreader_charboundaryfinds how many bytes of the character at the limit are missing from the inflated buffer, but askedgzfile_fillfor only n + missing bytes. When the buffer already held more than n bytes nothing new was read, and the character was cut. The inflated buffer ends inside a character whenever a 2048-byte read of compressed data does.Request the buffer length plus the missing bytes instead.
Fixes #92