Skip to content

Commit b4434b8

Browse files
vytautaskubiliusclaude
authored andcommitted
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 <noreply@anthropic.com>
1 parent ca6e1fa commit b4434b8

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎ext/zlib/zlib.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,6 +4085,7 @@ rb_gzreader_s_zcat(int argc, VALUE *argv, VALUE klass)
40854085
}
40864086
tmpbuf = gzfile_read_all(get_gzfile(obj), Qnil);
40874087
rb_str_cat(buf, RSTRING_PTR(tmpbuf), RSTRING_LEN(tmpbuf));
4088+
RB_GC_GUARD(tmpbuf);
40884089
}
40894090

40904091
rb_gzreader_read(0, 0, obj);

0 commit comments

Comments
 (0)