Bento4 v1.6.0-640 was discovered to contain an out-of-memory bug via the AP4_DataBuffer::ReallocateBuffer() function.
cpe:2.3:a:axiosys:bento4:1.6.0-640:*:*:*:*:*:*:*
8C7DB535-F27C-455F-9E99-3EF80B828022
OR
Hi,

Thanks for fixing the issue #741, but still there is out-of-memory bug in the latest version (1.6.0-640) of multiple programs because of the function AP4_DataBuffer::ReallocateBuffer() at Ap4DataBuffer.cpp:210.

We observed the same bug in mp4info, mp42aac, mp42avc, mp4decrypt, and mp4dump with the same root cause.

Here is the output of program with address sanitizer attached.

### Bug Report

=================================================================
==977537==ERROR: AddressSanitizer: allocator is out of memory trying to allocate 0x8021ffba bytes
    #0 0x7fb17bc08787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
    #1 0x557daf86f117 in AP4_DataBuffer::ReallocateBuffer(unsigned int) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DataBuffer.cpp:210
    #2 0x557daf86f319 in AP4_DataBuffer::SetDataSize(unsigned int) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DataBuffer.cpp:151
    #3 0x557daf8c68b2 in AP4_AudioSampleEntry::ReadFields(AP4_ByteStream&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:502
    #4 0x557daf8c5d98 in AP4_SampleEntry::Read(AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:108
    #5 0x557daf8cc2dd in AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:420
    #6 0x557daf8cc3d2 in AP4_MpegAudioSampleEntry::AP4_MpegAudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:655
    #7 0x557daf8cc3d2 in AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:844
    #8 0x557daf850a3b in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:286
    #9 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #10 0x557daf8dbac4 in AP4_StsdAtom::AP4_StsdAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4StsdAtom.cpp:101
    #11 0x557daf8dc09b in AP4_StsdAtom::Create(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4StsdAtom.cpp:57
    #12 0x557daf84f9d0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:458
    #13 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #14 0x557daf85f3ea in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:194
    #15 0x557daf85f793 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:139
    #16 0x557daf85fcbd in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:88
    #17 0x557daf84eca4 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:816
    #18 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #19 0x557daf872856 in AP4_DrefAtom::AP4_DrefAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DrefAtom.cpp:84
    #20 0x557daf872c33 in AP4_DrefAtom::Create(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DrefAtom.cpp:50
    #21 0x557daf84ecf4 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:580
    #22 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #23 0x557daf85f3ea in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:194
    #24 0x557daf85f793 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:139
    #25 0x557daf85fcbd in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:88
    #26 0x557daf84eca4 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:816
    #27 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #28 0x557daf85f3ea in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:194
    #29 0x557daf85f793 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:139
    #30 0x557daf85fcbd in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:88

==977537==HINT: if you don't care about these errors you may set allocator_may_return_null=1
SUMMARY: AddressSanitizer: out-of-memory ../../../../src/libsanitizer/asan/asan_new_delete.cc:107 in operator new[](unsigned long)
==977537==ABORTING

### Envionment
OS: Ubuntu 20.04.5 LTS x86_64
Release: v1.6.0-640
Program: mp4info, mp42aac, mp42avc, mp4decrypt, mp4dump

### How to reproduce
$ mp4info, mp4dump} poc-file
or 
$ {mp42aac, mp42avc, mp4decrypt} poc-file /dev/null
poc-file is attached.
[poc-file.txt](https://github.com/axiomatic-systems/Bento4/files/11720958/poc-file.txt)
Out-of-memory bug from AP4_DataBuffer::ReallocateBuffer() in multiple programs (v1.6.0-640)
This is a GitHub Issue
repo:Bento4
owner:axiomatic-systems
Title : Out-of-memory bug from AP4_DataBuffer::ReallocateBuffer() in multiple programs (v1.6.0-640)
Issue date:

--- start body ---
Hi,

Thanks for fixing the issue #741, but still there is out-of-memory bug in the latest version (1.6.0-640) of multiple programs because of the function AP4_DataBuffer::ReallocateBuffer() at Ap4DataBuffer.cpp:210.

We observed the same bug in mp4info, mp42aac, mp42avc, mp4decrypt, and mp4dump with the same root cause.

Here is the output of program with address sanitizer attached.

### Bug Report

=================================================================
==977537==ERROR: AddressSanitizer: allocator is out of memory trying to allocate 0x8021ffba bytes
    #0 0x7fb17bc08787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
    #1 0x557daf86f117 in AP4_DataBuffer::ReallocateBuffer(unsigned int) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DataBuffer.cpp:210
    #2 0x557daf86f319 in AP4_DataBuffer::SetDataSize(unsigned int) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DataBuffer.cpp:151
    #3 0x557daf8c68b2 in AP4_AudioSampleEntry::ReadFields(AP4_ByteStream&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:502
    #4 0x557daf8c5d98 in AP4_SampleEntry::Read(AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:108
    #5 0x557daf8cc2dd in AP4_AudioSampleEntry::AP4_AudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:420
    #6 0x557daf8cc3d2 in AP4_MpegAudioSampleEntry::AP4_MpegAudioSampleEntry(unsigned int, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:655
    #7 0x557daf8cc3d2 in AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4SampleEntry.cpp:844
    #8 0x557daf850a3b in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:286
    #9 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #10 0x557daf8dbac4 in AP4_StsdAtom::AP4_StsdAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4StsdAtom.cpp:101
    #11 0x557daf8dc09b in AP4_StsdAtom::Create(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4StsdAtom.cpp:57
    #12 0x557daf84f9d0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:458
    #13 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #14 0x557daf85f3ea in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:194
    #15 0x557daf85f793 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:139
    #16 0x557daf85fcbd in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:88
    #17 0x557daf84eca4 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:816
    #18 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #19 0x557daf872856 in AP4_DrefAtom::AP4_DrefAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DrefAtom.cpp:84
    #20 0x557daf872c33 in AP4_DrefAtom::Create(unsigned int, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4DrefAtom.cpp:50
    #21 0x557daf84ecf4 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:580
    #22 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #23 0x557daf85f3ea in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:194
    #24 0x557daf85f793 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:139
    #25 0x557daf85fcbd in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:88
    #26 0x557daf84eca4 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:816
    #27 0x557daf8524e0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned long long&, AP4_Atom*&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4AtomFactory.cpp:234
    #28 0x557daf85f3ea in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&, AP4_ByteStream&, unsigned long long) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:194
    #29 0x557daf85f793 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:139
    #30 0x557daf85fcbd in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&, AP4_AtomFactory&) /home/ubuntu/targets/Bento4-1.6.0-640_sanitizer/Source/C++/Core/Ap4ContainerAtom.cpp:88

==977537==HINT: if you don't care about these errors you may set allocator_may_return_null=1
SUMMARY: AddressSanitizer: out-of-memory ../../../../src/libsanitizer/asan/asan_new_delete.cc:107 in operator new[](unsigned long)
==977537==ABORTING

### Envionment
OS: Ubuntu 20.04.5 LTS x86_64
Release: v1.6.0-640
Program: mp4info, mp42aac, mp42avc, mp4decrypt, mp4dump

### How to reproduce
$ mp4info, mp4dump} poc-file
or 
$ {mp42aac, mp42avc, mp4decrypt} poc-file /dev/null
poc-file is attached.
[poc-file.txt](https://github.com/axiomatic-systems/Bento4/files/11720958/poc-file.txt)
--- end body ---

comments :
--- start comments ---

--- end comments ---