Skip to content

Commit

Permalink
Don't allow recursive decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 1, 2024
1 parent 07652b7 commit ce5523c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,7 @@ zstream_expand_buffer(struct zstream *z)
rb_obj_reveal(z->buf, rb_cString);
}

rb_mutex_unlock(z->mutex);
rb_protect(rb_yield, z->buf, &state);
rb_mutex_lock(z->mutex);
rb_protect(rb_yield, z->buf, &state);

if (ZSTREAM_REUSE_BUFFER_P(z)) {
rb_str_modify(z->buf);
Expand Down Expand Up @@ -729,6 +727,7 @@ zstream_expand_buffer_protect(struct zstream *z)

return state;
}

static int
zstream_expand_buffer_non_stream(struct zstream *z)
{
Expand Down Expand Up @@ -1207,7 +1206,11 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
.jump_state = 0,
.stream_output = !ZSTREAM_IS_GZFILE(z) && rb_block_given_p(),
};
rb_mutex_lock(z->mutex);

if (rb_mutex_trylock(z->mutex) == Qfalse) {
rb_raise(cInProgressError, "zlib stream is in progress");
}

rb_ensure(zstream_run_try, (VALUE)&args, zstream_run_ensure, (VALUE)&args);
if (args.jump_state)
rb_jump_tag(args.jump_state);
Expand Down

0 comments on commit ce5523c

Please sign in to comment.