Yahweasel / libav.js

This is a compilation of the libraries associated with handling audio and video in ffmpeg—libavformat, libavcodec, libavfilter, libavutil, libswresample, and libswscale—for emscripten, and thus the web.
288 stars 18 forks source link

Error while free'ing a dict #35

Closed reinhrst closed 7 months ago

reinhrst commented 8 months ago

Researching https://github.com/Yahweasel/libav.js/issues/34, I came to a smallest example that produces the error:

<!doctype html>
<html>
  <body>
    <script type="text/javascript">LibAV = {base: "/thirdparty/libav.js-4.5.6.0/dist"};</script>
    <script type="text/javascript" src="/thirdparty/libav.js-4.5.6.0/dist/libav-4.5.6.0-default.dbg.js"></script>
    <script type="text/javascript">(async function() {
      const libav = await LibAV.LibAV({noworker: true});
      const options = libav.av_dict_set_js_sync(0, "max_packet_size", "204800", 0)
      console.log({options})
      libav.av_dict_free_sync(options)
    })();
    </script>
  </body>
</html>

This results in the following error:

{"options": 2850176}
Uncaught (in promise) RuntimeError: memory access out of bounds
    at dlfree (dlmalloc.c:4786:24)
    at av_freep (mem.c:241:5)
    at av_dict_free (dict.c:234:5)
    at ret.<computed> (libav-4.5.6.0-default.dbg.simd.js:5120:35)
    at Module._av_dict_free [as av_dict_free_sync] (libav-4.5.6.0-default.dbg.simd.js:6813:84)
    at (index):10:13

Using the async versions of the av_dict_* functions results in the same errors.

Yahweasel commented 7 months ago

Like av_dict_set, av_dict_free takes a pointer-pointer, and the _js version takes a pointer. If you're using av_dict_set_js, you should be using av_dict_free_js.