Skip to content

Do not share the output buffer in Zlib::Deflate#initialize_copy - #161

Open
mame wants to merge 1 commit into
ruby:masterfrom
mame:zlib-deflate-dup-buffer
Open

mame wants to merge 1 commit into
ruby:masterfrom
mame:zlib-deflate-dup-buffer

Conversation

@mame

@mame mame commented Oct 24, 2026

Copy link
Copy Markdown
Member

The copy shared the buffer string with the original, and its next_out still pointed into the original's buffer.

  z1 = Zlib::Deflate.new
  z1 << Random.bytes(50_000)
  z2 = z1.dup
  z2 << "foo"
  #=> can't set length of shared string (RuntimeError)

The copy shared the buffer string with the original, and its next_out
still pointed into the original's buffer.

  z1 = Zlib::Deflate.new
  z1 << Random.bytes(50_000)
  z2 = z1.dup
  z2 << "foo"
  #=> can't set length of shared string (RuntimeError)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame
mame force-pushed the zlib-deflate-dup-buffer branch from a788a52 to 1ce3555 Compare October 24, 2026 20:17

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