Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!

- [x] I looked for a similar issue and couldn't find any.
- [x] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [x] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...). I can share files anonymously with this dropbox: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95

Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/

# Version

```
MP4Box - GPAC version 2.3-DEV-rev40-g3602a5ded-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io

Please cite our work in your research:
        GPAC Filters: https://doi.org/10.1145/3339825.3394929
        GPAC: https://doi.org/10.1145/1291233.1291452

GPAC Configuration: --enable-sanitizer --verbose
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_PNG GPAC_HAS_LINUX_DVB  GPAC_DISABLE_3D
```

# Reproduce
complie and run

```
./configure --enable-sanitizer --enable-debug
make
./MP4Box -info gf_av1_reset_state_poc
```

information reported by sanitizer

```
[AV1] VFR not supported.
=================================================================
==23845==ERROR: AddressSanitizer: attempting double-free on 0x615000013680 in thread T0:
    #0 0x7f62c61ab40f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
    #1 0x7f62c301d5b9 in gf_av1_reset_state media_tools/av_parsers.c:4024
    #2 0x7f62c3a6a901 in av1dmx_finalize filters/reframe_av1.c:1246
    #3 0x7f62c3643386 in gf_fs_del filter_core/filter_session.c:771
    #4 0x7f62c307e1ba in gf_media_import media_tools/media_import.c:1293
    #5 0x555b44f7c3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
    #6 0x555b44f4bdb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
    #7 0x7f62c0314082 in __libc_start_main ../csu/libc-start.c:308
    #8 0x555b44f1fcfd in _start (/home/qianshuidewajueji/gpac/bin/gcc/MP4Box+0xa3cfd)

0x615000013680 is located 0 bytes inside of 512-byte region [0x615000013680,0x615000013880)
freed by thread T0 here:
    #0 0x7f62c61abc3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
    #1 0x7f62c27ffcf5 in gf_bs_write_data utils/bitstream.c:1059
    #2 0x7f62c301bf5e in av1_add_obu_internal media_tools/av_parsers.c:2519
    #3 0x7f62c3021918 in aom_av1_parse_temporal_unit_from_section5 media_tools/av_parsers.c:2623
    #4 0x7f62c3a74a44 in av1dmx_parse_av1 filters/reframe_av1.c:1006
    #5 0x7f62c3a74f81 in av1dmx_process_buffer filters/reframe_av1.c:1084
    #6 0x7f62c3a757d5 in av1dmx_process filters/reframe_av1.c:1225
    #7 0x7f62c36700ed in gf_filter_process_task filter_core/filter.c:2828
    #8 0x7f62c3632082 in gf_fs_thread_proc filter_core/filter_session.c:1859
    #9 0x7f62c363e856 in gf_fs_run filter_core/filter_session.c:2120
    #10 0x7f62c307c806 in gf_media_import media_tools/media_import.c:1228
    #11 0x555b44f7c3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
    #12 0x555b44f4bdb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
    #13 0x7f62c0314082 in __libc_start_main ../csu/libc-start.c:308

previously allocated by thread T0 here:
    #0 0x7f62c61ab808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f62c27f8172 in gf_bs_new utils/bitstream.c:154
    #2 0x7f62c301c1a3 in av1_add_obu_internal media_tools/av_parsers.c:2492
    #3 0x7f62c3021918 in aom_av1_parse_temporal_unit_from_section5 media_tools/av_parsers.c:2623
    #4 0x7f62c3a715e4 in av1dmx_check_format filters/reframe_av1.c:269
    #5 0x7f62c3a74e9e in av1dmx_process_buffer filters/reframe_av1.c:1075
    #6 0x7f62c3a757d5 in av1dmx_process filters/reframe_av1.c:1225
    #7 0x7f62c36700ed in gf_filter_process_task filter_core/filter.c:2828
    #8 0x7f62c3632082 in gf_fs_thread_proc filter_core/filter_session.c:1859
    #9 0x7f62c363e856 in gf_fs_run filter_core/filter_session.c:2120
    #10 0x7f62c307c806 in gf_media_import media_tools/media_import.c:1228
    #11 0x555b44f7c3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
    #12 0x555b44f4bdb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
    #13 0x7f62c0314082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: double-free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122 in __interceptor_free
==23845==ABORTING
```

# Poc

https://github.com/qianshuidewajueji/poc/blob/main/gpac/gf_av1_reset_state_poc
double free in function  gf_bs_write_data utils/bitstream.c:1059
This is a GitHub Issue
repo:gpac
owner:gpac
Title : double free in function  gf_bs_write_data utils/bitstream.c:1059
Issue date:

--- start body ---
Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!

- [x] I looked for a similar issue and couldn't find any.
- [x] I tried with the latest version of GPAC. Installers available at http://gpac.io/downloads/gpac-nightly-builds/
- [x] I give enough information for contributors to reproduce my issue (meaningful title, github labels, platform and compiler, command-line ...). I can share files anonymously with this dropbox: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95

Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/

# Version

```
MP4Box - GPAC version 2.3-DEV-rev40-g3602a5ded-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io

Please cite our work in your research:
        GPAC Filters: https://doi.org/10.1145/3339825.3394929
        GPAC: https://doi.org/10.1145/1291233.1291452

GPAC Configuration: --enable-sanitizer --verbose
Features: GPAC_CONFIG_LINUX GPAC_64_BITS GPAC_HAS_IPV6 GPAC_HAS_SSL GPAC_HAS_SOCK_UN GPAC_MINIMAL_ODF GPAC_HAS_QJS GPAC_HAS_PNG GPAC_HAS_LINUX_DVB  GPAC_DISABLE_3D
```

# Reproduce
complie and run

```
./configure --enable-sanitizer --enable-debug
make
./MP4Box -info gf_av1_reset_state_poc
```

information reported by sanitizer

```
[AV1] VFR not supported.
=================================================================
==23845==ERROR: AddressSanitizer: attempting double-free on 0x615000013680 in thread T0:
    #0 0x7f62c61ab40f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
    #1 0x7f62c301d5b9 in gf_av1_reset_state media_tools/av_parsers.c:4024
    #2 0x7f62c3a6a901 in av1dmx_finalize filters/reframe_av1.c:1246
    #3 0x7f62c3643386 in gf_fs_del filter_core/filter_session.c:771
    #4 0x7f62c307e1ba in gf_media_import media_tools/media_import.c:1293
    #5 0x555b44f7c3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
    #6 0x555b44f4bdb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
    #7 0x7f62c0314082 in __libc_start_main ../csu/libc-start.c:308
    #8 0x555b44f1fcfd in _start (/home/qianshuidewajueji/gpac/bin/gcc/MP4Box+0xa3cfd)

0x615000013680 is located 0 bytes inside of 512-byte region [0x615000013680,0x615000013880)
freed by thread T0 here:
    #0 0x7f62c61abc3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
    #1 0x7f62c27ffcf5 in gf_bs_write_data utils/bitstream.c:1059
    #2 0x7f62c301bf5e in av1_add_obu_internal media_tools/av_parsers.c:2519
    #3 0x7f62c3021918 in aom_av1_parse_temporal_unit_from_section5 media_tools/av_parsers.c:2623
    #4 0x7f62c3a74a44 in av1dmx_parse_av1 filters/reframe_av1.c:1006
    #5 0x7f62c3a74f81 in av1dmx_process_buffer filters/reframe_av1.c:1084
    #6 0x7f62c3a757d5 in av1dmx_process filters/reframe_av1.c:1225
    #7 0x7f62c36700ed in gf_filter_process_task filter_core/filter.c:2828
    #8 0x7f62c3632082 in gf_fs_thread_proc filter_core/filter_session.c:1859
    #9 0x7f62c363e856 in gf_fs_run filter_core/filter_session.c:2120
    #10 0x7f62c307c806 in gf_media_import media_tools/media_import.c:1228
    #11 0x555b44f7c3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
    #12 0x555b44f4bdb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
    #13 0x7f62c0314082 in __libc_start_main ../csu/libc-start.c:308

previously allocated by thread T0 here:
    #0 0x7f62c61ab808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f62c27f8172 in gf_bs_new utils/bitstream.c:154
    #2 0x7f62c301c1a3 in av1_add_obu_internal media_tools/av_parsers.c:2492
    #3 0x7f62c3021918 in aom_av1_parse_temporal_unit_from_section5 media_tools/av_parsers.c:2623
    #4 0x7f62c3a715e4 in av1dmx_check_format filters/reframe_av1.c:269
    #5 0x7f62c3a74e9e in av1dmx_process_buffer filters/reframe_av1.c:1075
    #6 0x7f62c3a757d5 in av1dmx_process filters/reframe_av1.c:1225
    #7 0x7f62c36700ed in gf_filter_process_task filter_core/filter.c:2828
    #8 0x7f62c3632082 in gf_fs_thread_proc filter_core/filter_session.c:1859
    #9 0x7f62c363e856 in gf_fs_run filter_core/filter_session.c:2120
    #10 0x7f62c307c806 in gf_media_import media_tools/media_import.c:1228
    #11 0x555b44f7c3b1 in convert_file_info /home/qianshuidewajueji/gpac/applications/mp4box/fileimport.c:130
    #12 0x555b44f4bdb5 in mp4box_main /home/qianshuidewajueji/gpac/applications/mp4box/mp4box.c:6302
    #13 0x7f62c0314082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: double-free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122 in __interceptor_free
==23845==ABORTING
```

# Poc

https://github.com/qianshuidewajueji/poc/blob/main/gpac/gf_av1_reset_state_poc
--- end body ---
