## Description
There is a heap buffer overflow 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-rev1687-g16bd902cb-master
```

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

## crash command
```
MP4Box -dxml -out /dev/null poc_file
```

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



## Crash output
```
==18134==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000000eda at pc 0x000000cdd403 bp 0x7ffc94991ef0 sp 0x7ffc94991ee8
READ of size 1 at 0x611000000eda thread T0
    #0 0xcdd402 in gf_inspect_dump_nalu_internal /programs/mp4box/builds/build6/src/filters/inspect.c:1164:24
    #1 0xcd734f in gf_inspect_dump_nalu /programs/mp4box/builds/build6/src/filters/inspect.c:1206:2
    #2 0x4f45e3 in dump_isom_nal_ex /programs/mp4box/builds/build6/applications/mp4box/filedump.c:1288:5
    #3 0x4f8170 in dump_isom_xml /programs/mp4box/builds/build6/applications/mp4box/filedump.c:2001:9
    #4 0x4e0da8 in mp4boxMain /programs/mp4box/builds/build6/applications/mp4box/main.c:6171:7
    #5 0x7fec5aea30b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #6 0x41ea6d in _start (/programs/mp4box/builds/build6/bin/gcc/MP4Box+0x41ea6d)

0x611000000eda is located 0 bytes to the right of 218-byte region [0x611000000e00,0x611000000eda)
allocated by thread T0 here:
    #0 0x499ccd in malloc (/programs/mp4box/builds/build6/bin/gcc/MP4Box+0x499ccd)
    #1 0x841999 in Media_GetSample /programs/mp4box/builds/build6/src/isomedia/media.c:625:29
    #2 0x7d9e90 in gf_isom_get_sample_ex /programs/mp4box/builds/build6/src/isomedia/isom_read.c:1905:6
    #3 0x4f40a0 in dump_isom_nal_ex /programs/mp4box/builds/build6/applications/mp4box/filedump.c:1234:24
    #4 0x4f8170 in dump_isom_xml /programs/mp4box/builds/build6/applications/mp4box/filedump.c:2001:9
    #5 0x4e0da8 in mp4boxMain /programs/mp4box/builds/build6/applications/mp4box/main.c:6171:7
    #6 0x7fec5aea30b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-buffer-overflow /programs/mp4box/builds/build6/src/filters/inspect.c:1164:24 in gf_inspect_dump_nalu_internal
Shadow bytes around the buggy address:
  0x0c227fff8180: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
  0x0c227fff8190: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c227fff81a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c227fff81b0: fd fd fd fd fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff81c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c227fff81d0: 00 00 00 00 00 00 00 00 00 00 00[02]fa fa fa fa
  0x0c227fff81e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff81f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8220: fa fa fa fa fa fa fa fa fa fa fa fa 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
==18134==ABORTING
/collect/collec.sh: line 18: 18134 Aborted (core dumped) 
------------------------
```
There is a heap buffer overflow detected by AddressSanitizer
This is a GitHub Issue
repo:gpac
owner:gpac
Title : There is a heap buffer overflow detected by AddressSanitizer
Issue date:

--- start body ---
## Description
There is a heap buffer overflow 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-rev1687-g16bd902cb-master
```

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

## crash command
```
MP4Box -dxml -out /dev/null poc_file
```

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



## Crash output
```
==18134==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000000eda at pc 0x000000cdd403 bp 0x7ffc94991ef0 sp 0x7ffc94991ee8
READ of size 1 at 0x611000000eda thread T0
    #0 0xcdd402 in gf_inspect_dump_nalu_internal /programs/mp4box/builds/build6/src/filters/inspect.c:1164:24
    #1 0xcd734f in gf_inspect_dump_nalu /programs/mp4box/builds/build6/src/filters/inspect.c:1206:2
    #2 0x4f45e3 in dump_isom_nal_ex /programs/mp4box/builds/build6/applications/mp4box/filedump.c:1288:5
    #3 0x4f8170 in dump_isom_xml /programs/mp4box/builds/build6/applications/mp4box/filedump.c:2001:9
    #4 0x4e0da8 in mp4boxMain /programs/mp4box/builds/build6/applications/mp4box/main.c:6171:7
    #5 0x7fec5aea30b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #6 0x41ea6d in _start (/programs/mp4box/builds/build6/bin/gcc/MP4Box+0x41ea6d)

0x611000000eda is located 0 bytes to the right of 218-byte region [0x611000000e00,0x611000000eda)
allocated by thread T0 here:
    #0 0x499ccd in malloc (/programs/mp4box/builds/build6/bin/gcc/MP4Box+0x499ccd)
    #1 0x841999 in Media_GetSample /programs/mp4box/builds/build6/src/isomedia/media.c:625:29
    #2 0x7d9e90 in gf_isom_get_sample_ex /programs/mp4box/builds/build6/src/isomedia/isom_read.c:1905:6
    #3 0x4f40a0 in dump_isom_nal_ex /programs/mp4box/builds/build6/applications/mp4box/filedump.c:1234:24
    #4 0x4f8170 in dump_isom_xml /programs/mp4box/builds/build6/applications/mp4box/filedump.c:2001:9
    #5 0x4e0da8 in mp4boxMain /programs/mp4box/builds/build6/applications/mp4box/main.c:6171:7
    #6 0x7fec5aea30b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-buffer-overflow /programs/mp4box/builds/build6/src/filters/inspect.c:1164:24 in gf_inspect_dump_nalu_internal
Shadow bytes around the buggy address:
  0x0c227fff8180: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
  0x0c227fff8190: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c227fff81a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c227fff81b0: fd fd fd fd fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff81c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c227fff81d0: 00 00 00 00 00 00 00 00 00 00 00[02]fa fa fa fa
  0x0c227fff81e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff81f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8220: fa fa fa fa fa fa fa fa fa fa fa fa 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
==18134==ABORTING
/collect/collec.sh: line 18: 18134 Aborted (core dumped) 
------------------------
```
--- end body ---

A heap buffer overflow vulnerability in GPAC version 1.1.0-DEV can be exploited by providing a specially crafted MP4 file to the MP4Box application. This vulnerability is detected by AddressSanitizer and can lead to a crash or potential arbitrary code execution.