Bento4 icon indicating copy to clipboard operation
Bento4 copied to clipboard

heap-buffer-overflow in Ap4HvccAtom.cpp

Open shao-hua-li opened this issue 3 years ago • 0 comments

Hi there,

I found a heap-buffer-overflow in mp42aac with a fuzzer.

  • Bento4 version: v1.6.0-639 (commit 5abeaa0ebdb8c3be5b710517eb04d807832d2bbf)
  • Compiler args: DCMAKE_C_FLAGS=-fsanitize=address
  • Platform: Ubuntu 20.04.2 LTS, x86_64
  • Reproduce: mp42aac heap_Ap4HvccAtom_poc /dev/null
  • POC: heap_Ap4HvccAtom_poc.tar.gz (decompress it first)

AddressSanitizer report:

==91772==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6030000000e6 at pc 0x0000005b2df4 bp 0x7fffffe92d80 sp 0x7fffffe92d78
READ of size 1 at 0x6030000000e6 thread T0
    #0 0x5b2df3 in AP4_HvccAtom::AP4_HvccAtom(unsigned int, unsigned char const*) /mp42aac/repo/Source/C++/Core/Ap4HvccAtom.cpp:282:24
    #1 0x5ac910 in AP4_HvccAtom::Create(unsigned int, AP4_ByteStream&) /mp42aac/repo/Source/C++/Core/Ap4HvccAtom.cpp:90:16
    #2 0x54a89b in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /mp42aac/repo/Source/C++/Core/Ap4AtomFactory.cpp:518:20
    #3 0x547a4c in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /mp42aac/repo/Source/C++/Core/Ap4AtomFactory.cpp:234:14
    #4 0x54717e in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, AP4_Atom*&) /mp42aac/repo/Source/C++/Core/Ap4AtomFactory.cpp:154:12
    #5 0x4d4b1e in AP4_File::ParseStream(AP4_ByteStream&, AP4_AtomFactory&, bool) /mp42aac/repo/Source/C++/Core/Ap4File.cpp:104:12
    #6 0x4d5180 in AP4_File::AP4_File(AP4_ByteStream&, bool) /mp42aac/repo/Source/C++/Core/Ap4File.cpp:78:5
    #7 0x4cb2a1 in main /mp42aac/repo/Source/C++/Apps/Mp42Aac/Mp42Aac.cpp:250:22
    #8 0x7fc5e48d00b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #9 0x41c6cd in _start (/out_bin/mp42aac+0x41c6cd)

0x6030000000e6 is located 0 bytes to the right of 22-byte region [0x6030000000d0,0x6030000000e6)
allocated by thread T0 here:
    #0 0x4c875d in operator new[](unsigned long) (/out_bin/mp42aac+0x4c875d)
    #1 0x4d2e66 in AP4_DataBuffer::AP4_DataBuffer(unsigned int) /mp42aac/repo/Source/C++/Core/Ap4DataBuffer.cpp:55:16

SUMMARY: AddressSanitizer: heap-buffer-overflow /mp42aac/repo/Source/C++/Core/Ap4HvccAtom.cpp:282:24 in AP4_HvccAtom::AP4_HvccAtom(unsigned int, unsigned char const*)
Shadow bytes around the buggy address:
  0x0c067fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c067fff8000: fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa 00 00
=>0x0c067fff8010: 00 fa fa fa 00 00 00 fa fa fa 00 00[06]fa fa fa
  0x0c067fff8020: 00 00 06 fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c067fff8060: 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
==91772==ABORTING

shao-hua-li avatar Jul 30 '21 14:07 shao-hua-li