Skip to content

Detect a separator modified during Zlib::GzipReader#gets - #162

Open
mame wants to merge 1 commit into
ruby:masterfrom
mame:zlib-gets-rscheck
Open

mame wants to merge 1 commit into
ruby:masterfrom
mame:zlib-gets-rscheck

Conversation

@mame

@mame mame commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

rscheck required both the pointer and the length to change, so a separator reallocated to the same length was not detected and the freed pointer was read.

  rs = "-" * 1000
  src = StringIO.new(Zlib.gzip(Random.bytes(200_000).tr("-", "x") + rs))
  n = 0
  io = Object.new
  io.define_singleton_method(:readpartial) do |len, buf = nil|
    (rs.clear << "-" * 1000) if (n += 1) == 300
    src.readpartial(100, *buf)
  end
  Zlib::GzipReader.new(io).gets(rs)
  #=> heap-use-after-free READ (with ASAN)

rscheck required both the pointer and the length to change, so a
separator reallocated to the same length was not detected and the
freed pointer was read.

  rs = "-" * 1000
  src = StringIO.new(Zlib.gzip(Random.bytes(200_000).tr("-", "x") + rs))
  n = 0
  io = Object.new
  io.define_singleton_method(:readpartial) do |len, buf = nil|
    (rs.clear << "-" * 1000) if (n += 1) == 300
    src.readpartial(100, *buf)
  end
  Zlib::GzipReader.new(io).gets(rs)
  #=> heap-use-after-free READ (with ASAN)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant