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 5, 2024
1 parent 2fe600e commit 9966ce5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,12 +1053,16 @@ 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

// Assuming that `rb_nogvl` doesn't raise an exception, we don't need to deal with `rb_ensure`.
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 9966ce5

Please sign in to comment.