Project: gpac (gpac/gpac), language: c++
Vulnerability instance: gpac.cve-2024-0322
Sanitizer: address

================= Bug Report (1/1) ==================
## Source: Huntr
## URL: https://huntr.com/bounties/87611fc9-ed7c-43e9-8e52-d83cd270bbec
## Description:
Description
Heap-buffer-overflow in ac3dmx_process at filters/reframe_ac3.c:489.
version
git log
commit 5692dc729491805e0e5f55c21d50ba1e6b19e88e (HEAD -> master, origin/master, origin/HEAD)
Author: Aurelien David <aurelien.david@telecom-paristech.fr>
Date:   Wed Oct 11 13:24:46 2023 +0200

    ac3dmx: add remain size check (fixes #2627)

./MP4Box -version
MP4Box - GPAC version 2.3-DEV-rev577-g5692dc729-master
(c) 2000-2023 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
./configure --enable-sanitizer
make
Proof of Concept
./bin/gcc/MP4Box -dash 1000 -out /dev/null   poc_1
[Dasher] No template assigned, using $File$_dash$FS$$Number$
[AC3Dmx] 3 bytes unrecovered before sync word
Unknown CICP mapping for channel config 1/0.1
[FileOut] cannot open output file /dev/poc_1_dashinit.mp4
[FileOut] output file handle is not opened, discarding 809 bytes
[AC3Dmx] 14965 bytes unrecovered before sync word
=================================================================
==46129==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62800002bbf5 at pc 0x7ffff761e490 bp 0x7ffffffed8a0 sp 0x7ffffffed048
READ of size 128 at 0x62800002bbf5 thread T0
    #0 0x7ffff761e48f in __interceptor_memcpy ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790
    #1 0x7ffff4e8f3af in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
    #2 0x7ffff4e8f3af in ac3dmx_process filters/reframe_ac3.c:489
    #3 0x7ffff4a5f78e in gf_filter_process_task filter_core/filter.c:2971
    #4 0x7ffff4a2cdf1 in gf_fs_thread_proc filter_core/filter_session.c:2105
    #5 0x7ffff4a31b96 in gf_fs_run filter_core/filter_session.c:2405
    #6 0x7ffff43bd6bd in gf_dasher_process media_tools/dash_segmenter.c:1236
    #7 0x555555621d26 in do_dash /home/fuzz/gpac/applications/mp4box/mp4box.c:4831
    #8 0x555555621d26 in mp4box_main /home/fuzz/gpac/applications/mp4box/mp4box.c:6245
    #9 0x7ffff1650082 in __libc_start_main ../csu/libc-start.c:308
    #10 0x5555555fa05d in _start (/home/fuzz/gpac/bin/gcc/MP4Box+0xa605d)

0x62800002bbf5 is located 0 bytes to the right of 15093-byte region [0x628000028100,0x62800002bbf5)
allocated by thread T0 here:
    #0 0x7ffff7690c3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
    #1 0x7ffff4e8fa0a in ac3dmx_process filters/reframe_ac3.c:399
    #2 0x7ffff4a5f78e in gf_filter_process_task filter_core/filter.c:2971
    #3 0x7ffff4a2cdf1 in gf_fs_thread_proc filter_core/filter_session.c:2105
    #4 0x7ffff4a31b96 in gf_fs_run filter_core/filter_session.c:2405
    #5 0x7ffff43bd6bd in gf_dasher_process media_tools/dash_segmenter.c:1236
    #6 0x555555621d26 in do_dash /home/fuzz/gpac/applications/mp4box/mp4box.c:4831
    #7 0x555555621d26 in mp4box_main /home/fuzz/gpac/applications/mp4box/mp4box.c:6245
    #8 0x7ffff1650082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: heap-buffer-overflow ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:790 in __interceptor_memcpy
Shadow bytes around the buggy address:
  0x0c507fffd720: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c507fffd730: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c507fffd740: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c507fffd750: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c507fffd760: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c507fffd770: 00 00 00 00 00 00 00 00 00 00 00 00 00 00[05]fa
  0x0c507fffd780: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c507fffd790: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c507fffd7a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c507fffd7b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c507fffd7c0: 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
==46129==ABORTING
Proof of Concept
https://github.com/Janette88/test_pocs/blob/main/poc_1
Impact
An OOB read on the heap can potentially cause a crash or information disclosure in some cases. Could be leveraged with other vulnerabilities for a more serious impact.

Relevant Links:
https://github.com/gpac/gpac

Build script:
#!/bin/bash -eu
# Minimized build script with only core build commands
set -eu
./configure --static-build --extra-cflags="${CFLAGS}" --extra-ldflags="${CFLAGS}"
make -j$(nproc)

Dockerfile:
FROM hwiwonlee/secb.base:latest
RUN apt-get update && apt-get install -y build-essential pkg-config libz-dev
RUN git clone https://github.com/gpac/gpac gpac
RUN git -C gpac checkout 5692dc729491805e0e5f55c21d50ba1e6b19e88e
WORKDIR $SRC/gpac
COPY build.sh $SRC/

Additional files: