## Description
There is a heap-use-after-free detected by AddressSanitizer

## System info
```
Ubuntu 20.04.2 LTS
clang version 12.0.0-++20210402082642+04ba60cfe598-1~exp1~20210402063359.71
MP4Box - GPAC version 1.1.0-DEV-rev1671-g0cd19f4db-master
```

## Build command
```
./configure --static-mp4box --prefix=`realpath ./install` --enable-sanitizer --cc=clang --cxx=clang++
```

## crash command
MP4Box -frag 0 -out /dev/null poc_file

## Pocs
[poc.zip](https://github.com/gpac/gpac/files/7950841/poc.zip)

## Crash output
poc_35.mp4
```
==10012==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f000001d58 at pc 0x0000009a1eb3 bp 0x7ffd48bd83f0 sp 0x7ffd48bd83e8
READ of size 8 at 0x60f000001d58 thread T0
    #0 0x9a1eb2 in Media_GetESD /programs/mp4box/builds/build3/src/isomedia/media.c:213:49
    #1 0x9a7ca3 in Media_SetDuration /programs/mp4box/builds/build3/src/isomedia/media.c:860:4
    #2 0xa1d699 in SetTrackDuration /programs/mp4box/builds/build3/src/isomedia/track.c:386:6
    #3 0x995aa3 in gf_isom_update_duration /programs/mp4box/builds/build3/src/isomedia/isom_write.c:7491:27
    #4 0x906066 in gf_isom_get_duration /programs/mp4box/builds/build3/src/isomedia/isom_read.c:970:2
    #5 0x9c68db in gf_isom_finalize_for_fragment programs/mp4box/builds/build3/src/isomedia/movie_fragments.c:115:4
    #6 0x100f896 in mp4_mux_initialize_movie /programs/mp4box/builds/build3/src/filters/mux_isom.c:5003:6
    #7 0x100f896 in mp4_mux_process_fragmented /programs/mp4box/builds/build3/src/filters/mux_isom.c:5315:7
    #8 0x10029a1 in mp4_mux_process /programs/mp4box/builds/build3/src/filters/mux_isom.c:6029:14
    #9 0xd8d4e9 in gf_filter_process_task /programs/mp4box/builds/build3/src/filter_core/filter.c:2515:7
    #10 0xd647ef in gf_fs_thread_proc /programs/mp4box/builds/build3/src/filter_core/filter_session.c:1756:3
    #11 0xd63523 in gf_fs_run /programs/mp4box/builds/build3/src/filter_core/filter_session.c:2000:2
    #12 0xaa99ff in gf_media_fragment_file /programs/mp4box/builds/build3/src/media_tools/isom_tools.c:3816:6
    #13 0x4ebaff in mp4boxMain /programs/mp4box/builds/build3/applications/mp4box/main.c:6455:7
    #14 0x7f56c11820b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #15 0x41ea6d in _start (/programs/mp4box/builds/build3/bin/gcc/MP4Box+0x41ea6d)

0x60f000001d58 is located 8 bytes inside of 176-byte region [0x60f000001d50,0x60f000001e00)
freed by thread T0 here:
    #0 0x499a62 in free (/programs/mp4box/builds/build3/bin/gcc/MP4Box+0x499a62)
    #1 0x998ced in gf_isom_update_sample_description_from_template /programs/mp4box/builds/build3/src/isomedia/isom_write.c:7757:2
    #2 0x1029564 in mp4_mux_setup_pid /programs/mp4box/builds/build3/src/filters/mux_isom.c:3102:4
    #3 0xd05416 in gf_filter_pid_configure/programs/mp4box/builds/build3/src/filter_core/filter_pid.c:752:6
    #4 0xd216b9 in gf_filter_pid_connect_task /programs/mp4box/builds/build3/src/filter_core/filter_pid.c:1061:3
    #5 0xd647ef in gf_fs_thread_proc /programs/mp4box/builds/build3/src/filter_core/filter_session.c:1756:3
    #6 0xd63523 in gf_fs_run /programs/mp4box/builds/build3/src/filter_core/filter_session.c:2000:2
    #7 0xaa99ff in gf_media_fragment_file /mp4box/builds/build3/src/media_tools/isom_tools.c:3816:6
    #8 0x4ebaff in mp4boxMain /programs/mp4box/builds/build3/applications/mp4box/main.c:6455:7
    #9 0x7f56c11820b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

previously allocated by thread T0 here:
    #0 0x499ccd in malloc (/programs/mp4box/builds/build3/bin/gcc/MP4Box+0x499ccd)
    #1 0x54ef20 in gf_bs_new /programs/mp4box/builds/build3/src/utils/bitstream.c:129:38
    #2 0x998ccd in gf_isom_update_sample_description_from_template /programs/mp4box/builds/build3/src/isomedia/isom_write.c:7754:7
    #3 0x1029564 in mp4_mux_setup_pid /programs/mp4box/builds/build3/src/filters/mux_isom.c:3102:4
    #4 0xd05416 in gf_filter_pid_configure /programs/mp4box/builds/build3/src/filter_core/filter_pid.c:752:6
    #5 0xd216b9 in gf_filter_pid_connect_task /programs/mp4box/builds/build3/src/filter_core/filter_pid.c:1061:3
    #6 0xd647ef in gf_fs_thread_proc /programs/mp4box/builds/build3/src/filter_core/filter_session.c:1756:3
    #7 0xd63523 in gf_fs_run/programs/mp4box/builds/build3/src/filter_core/filter_session.c:2000:2
    #8 0xaa99ff in gf_media_fragment_file /programs/mp4box/builds/build3/src/media_tools/isom_tools.c:3816:6
    #9 0x4ebaff in mp4boxMain /programs/mp4box/builds/build3/applications/mp4box/main.c:6455:7
    #10 0x7f56c11820b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-use-after-free /programs/mp4box/builds/build3/src/isomedia/media.c:213:49 in Media_GetESD
Shadow bytes around the buggy address:
  0x0c1e7fff8350: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff8360: fd fd fd fd fd fd fa fa fa fa fa fa fa fa fd fd
  0x0c1e7fff8370: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff8380: fd fd fd fd fa fa fa fa fa fa fa fa 00 00 00 00
  0x0c1e7fff8390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c1e7fff83a0: 00 00 fa fa fa fa fa fa fa fa fd[fd]fd fd fd fd
  0x0c1e7fff83b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff83c0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c1e7fff83d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa
  0x0c1e7fff83e0: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff83f0: fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==10012==ABORTING
```
There is a heap-use-after-free detected by AddressSanitizer
This is a GitHub Issue
repo:gpac
owner:gpac
Title : There is a heap-use-after-free detected by AddressSanitizer
Issue date:

--- start body ---
## Description
There is a heap-use-after-free detected by AddressSanitizer

## System info
```
Ubuntu 20.04.2 LTS
clang version 12.0.0-++20210402082642+04ba60cfe598-1~exp1~20210402063359.71
MP4Box - GPAC version 1.1.0-DEV-rev1671-g0cd19f4db-master
```

## Build command
```
./configure --static-mp4box --prefix=`realpath ./install` --enable-sanitizer --cc=clang --cxx=clang++
```

## crash command
MP4Box -frag 0 -out /dev/null poc_file

## Pocs
[poc.zip](https://github.com/gpac/gpac/files/7950841/poc.zip)

## Crash output
poc_35.mp4
```
==10012==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f000001d58 at pc 0x0000009a1eb3 bp 0x7ffd48bd83f0 sp 0x7ffd48bd83e8
READ of size 8 at 0x60f000001d58 thread T0
    #0 0x9a1eb2 in Media_GetESD /programs/mp4box/builds/build3/src/isomedia/media.c:213:49
    #1 0x9a7ca3 in Media_SetDuration /programs/mp4box/builds/build3/src/isomedia/media.c:860:4
    #2 0xa1d699 in SetTrackDuration /programs/mp4box/builds/build3/src/isomedia/track.c:386:6
    #3 0x995aa3 in gf_isom_update_duration /programs/mp4box/builds/build3/src/isomedia/isom_write.c:7491:27
    #4 0x906066 in gf_isom_get_duration /programs/mp4box/builds/build3/src/isomedia/isom_read.c:970:2
    #5 0x9c68db in gf_isom_finalize_for_fragment programs/mp4box/builds/build3/src/isomedia/movie_fragments.c:115:4
    #6 0x100f896 in mp4_mux_initialize_movie /programs/mp4box/builds/build3/src/filters/mux_isom.c:5003:6
    #7 0x100f896 in mp4_mux_process_fragmented /programs/mp4box/builds/build3/src/filters/mux_isom.c:5315:7
    #8 0x10029a1 in mp4_mux_process /programs/mp4box/builds/build3/src/filters/mux_isom.c:6029:14
    #9 0xd8d4e9 in gf_filter_process_task /programs/mp4box/builds/build3/src/filter_core/filter.c:2515:7
    #10 0xd647ef in gf_fs_thread_proc /programs/mp4box/builds/build3/src/filter_core/filter_session.c:1756:3
    #11 0xd63523 in gf_fs_run /programs/mp4box/builds/build3/src/filter_core/filter_session.c:2000:2
    #12 0xaa99ff in gf_media_fragment_file /programs/mp4box/builds/build3/src/media_tools/isom_tools.c:3816:6
    #13 0x4ebaff in mp4boxMain /programs/mp4box/builds/build3/applications/mp4box/main.c:6455:7
    #14 0x7f56c11820b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #15 0x41ea6d in _start (/programs/mp4box/builds/build3/bin/gcc/MP4Box+0x41ea6d)

0x60f000001d58 is located 8 bytes inside of 176-byte region [0x60f000001d50,0x60f000001e00)
freed by thread T0 here:
    #0 0x499a62 in free (/programs/mp4box/builds/build3/bin/gcc/MP4Box+0x499a62)
    #1 0x998ced in gf_isom_update_sample_description_from_template /programs/mp4box/builds/build3/src/isomedia/isom_write.c:7757:2
    #2 0x1029564 in mp4_mux_setup_pid /programs/mp4box/builds/build3/src/filters/mux_isom.c:3102:4
    #3 0xd05416 in gf_filter_pid_configure/programs/mp4box/builds/build3/src/filter_core/filter_pid.c:752:6
    #4 0xd216b9 in gf_filter_pid_connect_task /programs/mp4box/builds/build3/src/filter_core/filter_pid.c:1061:3
    #5 0xd647ef in gf_fs_thread_proc /programs/mp4box/builds/build3/src/filter_core/filter_session.c:1756:3
    #6 0xd63523 in gf_fs_run /programs/mp4box/builds/build3/src/filter_core/filter_session.c:2000:2
    #7 0xaa99ff in gf_media_fragment_file /mp4box/builds/build3/src/media_tools/isom_tools.c:3816:6
    #8 0x4ebaff in mp4boxMain /programs/mp4box/builds/build3/applications/mp4box/main.c:6455:7
    #9 0x7f56c11820b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

previously allocated by thread T0 here:
    #0 0x499ccd in malloc (/programs/mp4box/builds/build3/bin/gcc/MP4Box+0x499ccd)
    #1 0x54ef20 in gf_bs_new /programs/mp4box/builds/build3/src/utils/bitstream.c:129:38
    #2 0x998ccd in gf_isom_update_sample_description_from_template /programs/mp4box/builds/build3/src/isomedia/isom_write.c:7754:7
    #3 0x1029564 in mp4_mux_setup_pid /programs/mp4box/builds/build3/src/filters/mux_isom.c:3102:4
    #4 0xd05416 in gf_filter_pid_configure /programs/mp4box/builds/build3/src/filter_core/filter_pid.c:752:6
    #5 0xd216b9 in gf_filter_pid_connect_task /programs/mp4box/builds/build3/src/filter_core/filter_pid.c:1061:3
    #6 0xd647ef in gf_fs_thread_proc /programs/mp4box/builds/build3/src/filter_core/filter_session.c:1756:3
    #7 0xd63523 in gf_fs_run/programs/mp4box/builds/build3/src/filter_core/filter_session.c:2000:2
    #8 0xaa99ff in gf_media_fragment_file /programs/mp4box/builds/build3/src/media_tools/isom_tools.c:3816:6
    #9 0x4ebaff in mp4boxMain /programs/mp4box/builds/build3/applications/mp4box/main.c:6455:7
    #10 0x7f56c11820b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-use-after-free /programs/mp4box/builds/build3/src/isomedia/media.c:213:49 in Media_GetESD
Shadow bytes around the buggy address:
  0x0c1e7fff8350: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff8360: fd fd fd fd fd fd fa fa fa fa fa fa fa fa fd fd
  0x0c1e7fff8370: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff8380: fd fd fd fd fa fa fa fa fa fa fa fa 00 00 00 00
  0x0c1e7fff8390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c1e7fff83a0: 00 00 fa fa fa fa fa fa fa fa fd[fd]fd fd fd fd
  0x0c1e7fff83b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff83c0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c1e7fff83d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa
  0x0c1e7fff83e0: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff83f0: fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==10012==ABORTING
```
--- end body ---
