From 98d706d46b60a334b3499a93fdf0b63b6cf17fe9 Mon Sep 17 00:00:00 2001 From: Vytautas Kubilius Date: Tue, 17 Nov 2026 10:31:28 +0200 Subject: [PATCH] Keep the inflated member alive in GzipReader.zcat Zlib::GzipReader.zcat copied each inflated member into the result with rb_str_cat, but nothing referenced the member string after its pointer and length were read, so a GC triggered while growing the result could free it in the middle of the copy. With members of tens of MB this crashed in memcpy, or returned data of the right length that was all NUL bytes or otherwise corrupted. Co-Authored-By: Claude Opus 5.5 --- ext/zlib/zlib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index e279bb9..81cdbe6 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -4068,6 +4068,7 @@ rb_gzreader_s_zcat(int argc, VALUE *argv, VALUE klass) } tmpbuf = gzfile_read_all(get_gzfile(obj), Qnil); rb_str_cat(buf, RSTRING_PTR(tmpbuf), RSTRING_LEN(tmpbuf)); + RB_GC_GUARD(tmpbuf); } rb_gzreader_read(0, 0, obj);