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

================= Bug Report (1/2) ==================
## Source: GitHub Issue
## URL: https://github.com/gpac/gpac/issues/1568
## Description:
Issue: gpac/gpac#1568
Title: A heap-buffer-overflow in box_code_adobe.c:124
State: closed
Created by: seviezhou
Created at: 2020-08-07 04:41:36+00:00

Issue Body:
## System info

Ubuntu x86_64, gcc (Ubuntu 5.5.0-12ubuntu1), MP4Box (latest master [2aa266](https://github.com/gpac/gpac/commit/2aa266dfaab6aaad9f9f4f216ad7d1e62adc7fa0))

## Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure --static-mp4box

## Command line

./bin/gcc/MP4Box -diso -out /dev/null @@

## AddressSanitizer output

```
=================================================================
==24631==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000e114 at pc 0x7f2a609a93d5 bp 0x7ffe7daf8840 sp 0x7ffe7daf7fe8
READ of size 5 at 0x60200000e114 thread T0
    #0 0x7f2a609a93d4 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x623d4)
    #1 0x55979e0874b7 in abst_box_read isomedia/box_code_adobe.c:124
    #2 0x55979de76b64 in gf_isom_box_read isomedia/box_funcs.c:1681
    #3 0x55979de76b64 in gf_isom_box_parse_ex isomedia/box_funcs.c:259
    #4 0x55979de78041 in gf_isom_parse_root_box isomedia/box_funcs.c:38
    #5 0x55979deaf6f5 in gf_isom_parse_movie_boxes isomedia/isom_intern.c:259
    #6 0x55979deba951 in gf_isom_parse_movie_boxes isomedia/isom_intern.c:247
    #7 0x55979deba951 in gf_isom_open_file isomedia/isom_intern.c:740
    #8 0x55979d7e47e3 in mp4boxMain /home/seviezhou/gpac/applications/mp4box/main.c:5331
    #9 0x7f2a5f973b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #10 0x55979d7b5f09 in _start (/home/seviezhou/gpac/bin/gcc/MP4Box+0x27ff09)

0x60200000e114 is located 0 bytes to the right of 4-byte region [0x60200000e110,0x60200000e114)
allocated by thread T0 here:
    #0 0x7f2a609df612 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98612)
    #1 0x55979e0853a9 in abst_box_read isomedia/box_code_adobe.c:97

SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 strdup
Shadow bytes around the buggy address:
  0x0c047fff9bd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9be0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9bf0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9c00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9c10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa 02 fa
=>0x0c047fff9c20: fa fa[04]fa fa fa 00 00 fa fa 00 00 fa fa 00 00
  0x0c047fff9c30: fa fa 00 00 fa fa 00 00 fa fa fd fa fa fa 00 fa
  0x0c047fff9c40: fa fa 00 00 fa fa 00 00 fa fa 00 07 fa fa fd fa
  0x0c047fff9c50: fa fa 00 02 fa fa 04 fa fa fa fd fa fa fa 07 fa
  0x0c047fff9c60: fa fa fd fa fa fa 05 fa fa fa fd fa fa fa 00 fa
  0x0c047fff9c70: fa fa fd fa fa fa 07 fa fa fa fd fa fa fa 07 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  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
==24631==ABORTING
```

## POC

[heap-overflow-abst_box_read-box_code_adobe-124.zip](https://github.com/gpac/gpac/files/5039356/heap-overflow-abst_box_read-box_code_adobe-124.zip)



Attachments:
https://github.com/gpac/gpac/files/5039356/heap-overflow-abst_box_read-box_code_adobe-124.zip

Commit References:
2aa266dfaab6aaad9f9f4f216ad7d1e62adc7fa0

================= Bug Report (2/2) ==================
## Source: GitHub Issue
## URL: https://github.com/gpac/gpac/issues/1569
## Description:
Issue: gpac/gpac#1569
Title: A heap-buffer-overflow in box_code_adobe.c:141
State: closed
Created by: seviezhou
Created at: 2020-08-07 14:53:11+00:00

Issue Body:
## System info

Ubuntu x86_64, gcc (Ubuntu 5.5.0-12ubuntu1), MP4Box (latest master [2aa266](https://github.com/gpac/gpac/commit/2aa266dfaab6aaad9f9f4f216ad7d1e62adc7fa0))

## Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure --static-mp4box

## Command line

./bin/gcc/MP4Box -diso -out /dev/null @@

## AddressSanitizer output

```
=================================================================
==73339==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000e2d3 at pc 0x7f61cb5fc3d5 bp 0x7ffc8913b6b0 sp 0x7ffc8913ae58
READ of size 20 at 0x60300000e2d3 thread T0
    #0 0x7f61cb5fc3d4 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x623d4)
    #1 0x56330736c407 in abst_box_read isomedia/box_code_adobe.c:141
    #2 0x56330715bb64 in gf_isom_box_read isomedia/box_funcs.c:1681
    #3 0x56330715bb64 in gf_isom_box_parse_ex isomedia/box_funcs.c:259
    #4 0x56330715d041 in gf_isom_parse_root_box isomedia/box_funcs.c:38
    #5 0x5633071946f5 in gf_isom_parse_movie_boxes isomedia/isom_intern.c:259
    #6 0x56330719f951 in gf_isom_parse_movie_boxes isomedia/isom_intern.c:247
    #7 0x56330719f951 in gf_isom_open_file isomedia/isom_intern.c:740
    #8 0x563306ac97e3 in mp4boxMain /home/seviezhou/gpac/applications/mp4box/main.c:5331
    #9 0x7f61ca5c6b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #10 0x563306a9af09 in _start (/home/seviezhou/gpac/bin/gcc/MP4Box+0x27ff09)

0x60300000e2d3 is located 0 bytes to the right of 19-byte region [0x60300000e2c0,0x60300000e2d3)
allocated by thread T0 here:
    #0 0x7f61cb632612 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98612)
    #1 0x56330736a3a9 in abst_box_read isomedia/box_code_adobe.c:97

SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 strdup
Shadow bytes around the buggy address:
  0x0c067fff9c00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9c10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9c20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9c30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff9c40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c067fff9c50: fa fa fa fa fa fa fa fa 00 00[03]fa fa fa 00 00
  0x0c067fff9c60: 04 fa fa fa 00 00 00 07 fa fa 00 00 00 fa fa fa
  0x0c067fff9c70: 00 00 00 06 fa fa 00 00 00 fa fa fa 00 00 00 fa
  0x0c067fff9c80: fa fa 00 00 00 07 fa fa 00 00 00 fa fa fa 00 00
  0x0c067fff9c90: 00 fa fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa
  0x0c067fff9ca0: 00 00 00 fa fa fa 00 00 00 fa fa fa 00 00 00 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  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
==73339==ABORTING
```

## POC

[heap-overflow-abst_box_read-box_code_adobe-141.zip](https://github.com/gpac/gpac/files/5042085/heap-overflow-abst_box_read-box_code_adobe-141.zip)



Comments:
Comment by jeanlf on 2020-09-01 15:16:26+00:00:
fixed by #1568 

Attachments:
https://github.com/gpac/gpac/files/5042085/heap-overflow-abst_box_read-box_code_adobe-141.zip

Commit References:
2aa266dfaab6aaad9f9f4f216ad7d1e62adc7fa0

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 ce01bd15f711d4575b7424b54b3a395ec64c1784
WORKDIR $SRC/gpac
COPY build.sh $SRC/

Additional files:
filename: fuzz_parse.c
content: /* Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdio.h>
#include <unistd.h>

#include <gpac/internal/isomedia_dev.h>
#include <gpac/constants.h>

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    char filename[256];
    sprintf(filename, "/tmp/libfuzzer.%d", getpid());

    FILE *fp = fopen(filename, "wb");
    if (!fp) {
        return 0;
    }
    fwrite(data, size, 1, fp);
    fclose(fp);

    GF_ISOFile *movie = NULL;
    movie = gf_isom_open_file(filename, GF_ISOM_OPEN_READ_DUMP, NULL);
    if (movie != NULL) {
        gf_isom_close(movie);
    }
    unlink(filename);
    return 0;
}