Skip to content

Fix Zlib::GzipReader#gets with a limit shorter than the separator - #155

Open
mame wants to merge 2 commits into
ruby:masterfrom
mame:zlib-gets-limit-fix
Open

mame wants to merge 2 commits into
ruby:masterfrom
mame:zlib-gets-limit-fix

Conversation

@mame

@mame mame commented Oct 24, 2026

Copy link
Copy Markdown
Member

The limit made the scanned length smaller than the separator, and the negative length was passed to memchr.

Zlib::GzipReader.new(StringIO.new(Zlib.gzip("abc"))).gets("xyz", 1)
# expected: "a"
# actual:   "abc" ([BUG] Segmentation fault with ASAN)

Co-authored-by: Masamune (https://hackerone.com/masamune_)

@mame
mame requested a review from nobu October 24, 2026 18:27
Comment thread ext/zlib/zlib.c Resolved
mame and others added 2 commits November 19, 2026 17:27
The limit made the scanned length smaller than the separator, and the
negative length was passed to memchr.

  Zlib::GzipReader.new(StringIO.new(Zlib.gzip("abc"))).gets("xyz", 1)
  # expected: "a"
  # actual:   "abc" ([BUG] Segmentation fault with ASAN)

Co-authored-by: Masamune (https://hackerone.com/masamune_)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…separator

When fewer bytes than the separator remained at the end of the stream,
all of them were returned regardless of the limit.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@mame
mame force-pushed the zlib-gets-limit-fix branch from f26c5b8 to 5822251 Compare November 19, 2026 08:39

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.

2 participants