Skip to content

Commit

Permalink
Add more protections around ocaml values.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Dec 25, 2024
1 parent 987ee5c commit 10a7622
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.5.2 (unreleased)
======
* Add more protection around ocaml values.

0.5.1 (2024-12-21)
=====
* Use generational global roots to protect
Expand Down
14 changes: 8 additions & 6 deletions src/flac_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,11 @@ FLAC__StreamDecoderReadStatus static dec_read_callback(
caml_register_generational_global_root(&data);
caml_register_generational_global_root(&ret);

data = caml_alloc_string(readlen);
caml_modify_generational_global_root(&data, caml_alloc_string(readlen));

ret = caml_callback3_exn(Dec_read(callbacks->callbacks), data, Val_int(0),
Val_int(readlen));
caml_modify_generational_global_root(
&ret, caml_callback3_exn(Dec_read(callbacks->callbacks), data, Val_int(0),
Val_int(readlen)));

if (Is_exception_result(ret)) {
caml_remove_generational_global_root(&data);
Expand Down Expand Up @@ -418,7 +419,7 @@ dec_write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame,
caml_register_generational_global_root(&data);
caml_register_generational_global_root(&ret);

data = caml_alloc_tuple(channels);
caml_modify_generational_global_root(&data, caml_alloc_tuple(channels));

int c, i;
for (c = 0; c < channels; c++) {
Expand Down Expand Up @@ -690,11 +691,12 @@ enc_write_callback(const FLAC__StreamEncoder *encoder,
caml_register_generational_global_root(&buf);
caml_register_generational_global_root(&res);

buf = caml_alloc_string(bytes);
caml_modify_generational_global_root(&buf, caml_alloc_string(bytes));

memcpy(Bytes_val(buf), buffer, bytes);

res = caml_callback_exn(Enc_write(callbacks), buf);
caml_modify_generational_global_root(
&res, caml_callback_exn(Enc_write(callbacks), buf));

if (Is_exception_result(res)) {
caml_remove_generational_global_root(&buf);
Expand Down

0 comments on commit 10a7622

Please sign in to comment.