Skip to content

Commit

Permalink
Fix possible access to fromspace in MVM_decoder_take_bytes
Browse files Browse the repository at this point in the history
Allocating the result buffer may trigger a GC run during which the decoder
pointer may become outdated. Move the allocation to after we're done with the
decoder, as we don't need the result buffer until then anyway.
  • Loading branch information
niner committed Apr 24, 2020
1 parent 8333393 commit f9ca5cb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/6model/reprs/Decoder.c
Expand Up @@ -329,10 +329,12 @@ MVMObject * MVM_decoder_take_bytes(MVMThreadContext *tc, MVMDecoder *decoder,
if (MVM_string_decodestream_bytes_available(tc, ds) < bytes)
return tc->instance->VMNull;

result = MVM_repr_alloc_init(tc, buf_type);
enter_single_user(tc, decoder);
read = MVM_string_decodestream_bytes_to_buf(tc, ds, &buf, bytes);
exit_single_user(tc, decoder);

/* Allocate after we're done with decoder to avoid having to MVMROOT */
result = MVM_repr_alloc_init(tc, buf_type);
((MVMArray *)result)->body.slots.i8 = (MVMint8 *)buf;
((MVMArray *)result)->body.start = 0;
((MVMArray *)result)->body.ssize = read;
Expand Down

0 comments on commit f9ca5cb

Please sign in to comment.