Skip to content

Commit

Permalink
Add rb_str_locktmp to prevent accidental modifications of z->buf.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 4, 2024
1 parent 2fe600e commit 3d2f241
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,12 +1053,15 @@ zstream_run_func(struct zstream_run_args *args)
while (!args->interrupt) {
n = z->stream.avail_out;

rb_str_locktmp(z->buf);

#ifndef RB_NOGVL_UBF_ASYNC_SAFE
err = (int)(VALUE)rb_thread_call_without_gvl(zstream_run_once, (void *)args, zstream_unblock_func, (void *)args);
#else
err = (int)(VALUE)rb_nogvl(zstream_run_once, (void *)args, zstream_unblock_func, (void *)args, RB_NOGVL_UBF_ASYNC_SAFE);
#endif

rb_str_unlocktmp(z->buf);
rb_str_set_len(z->buf, ZSTREAM_BUF_FILLED(z) + (n - z->stream.avail_out));

if (err == Z_STREAM_END) {
Expand Down

0 comments on commit 3d2f241

Please sign in to comment.