Skip to content

Commit 9966ce5

Browse files
committed
Add rb_str_locktmp to prevent accidental modifications of z->buf.
1 parent 2fe600e commit 9966ce5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ext/zlib/zlib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,16 @@ zstream_run_func(struct zstream_run_args *args)
10531053
while (!args->interrupt) {
10541054
n = z->stream.avail_out;
10551055

1056+
rb_str_locktmp(z->buf);
1057+
10561058
#ifndef RB_NOGVL_UBF_ASYNC_SAFE
10571059
err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_once, (void *)args, zstream_unblock_func, (void *)args);
10581060
#else
10591061
err = (int)(VALUE)rb_nogvl(zstream_run_once, (void *)args, zstream_unblock_func, (void *)args, RB_NOGVL_UBF_ASYNC_SAFE);
10601062
#endif
10611063

1064+
// Assuming that `rb_nogvl` doesn't raise an exception, we don't need to deal with `rb_ensure`.
1065+
rb_str_unlocktmp(z->buf);
10621066
rb_str_set_len(z->buf, ZSTREAM_BUF_FILLED(z) + (n - z->stream.avail_out));
10631067

10641068
if (err == Z_STREAM_END) {

0 commit comments

Comments
 (0)