overflow of Ap4Array.h in function EnsureCapacity

Hi
I found an crash erro.

System info：
Ubuntu 20.04 : clang 10.0.0 , gcc 9.3.0

Bento4 version 1.6.0.0

commit:0c7705733de80172712e487dd6fdd28387fd7184

[poc.zip](https://github.com/axiomatic-systems/Bento4/files/6469891/poc5.zip)

------------------------------------------
Verification steps：
1.Get the source code of Bento4
2.Compile the Bento4

```bash
$ cd Bento4
$ mkdir check_build && cd check_build
$ cmake ../ -DCMAKE_C_COMPILER=clang  -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="-fsanitize=address" -DCMAKE_CXX_FLAGS="-fsanitize=address"
$ make -j 32
```

3.run mp4tag
```bash
$ ./mp4tag poc  
```

asan info
```bash
=================================================================
==4151181==ERROR: AddressSanitizer: allocator is out of memory trying to allocate 0x6d6574610 bytes
    #0 0x4c48fd in operator new(unsigned long) (/home/hh/Downloads/Bento4/target/mp4tag+0x4c48fd)
    #1 0x61752f in AP4_Array<AP4_TrunAtom::Entry>::EnsureCapacity(unsigned int) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4Array.h:172:25
    #2 0x61752f in AP4_Array<AP4_TrunAtom::Entry>::SetItemCount(unsigned int) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4Array.h:210:25
    #3 0x61752f in AP4_TrunAtom::AP4_TrunAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4TrunAtom.cpp:127:15
    #4 0x616bca in AP4_TrunAtom::Create(unsigned int, AP4_ByteStream&) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4TrunAtom.cpp:51:16
    #5 0x4e0f81 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:429:20

==4151181==HINT: if you don't care about these errors you may set allocator_may_return_null=1
SUMMARY: AddressSanitizer: out-of-memory (/home/hh/Downloads/Bento4/target/mp4tag+0x4c48fd) in operator new(unsigned long)
==4151181==ABORTING
```

gdb info
```bash
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Program received signal SIGABRT, Aborted.
[----------------------------------registers-----------------------------------]
RAX: 0x0 
RBX: 0x7ffff7a77f40 (0x00007ffff7a77f40)
RCX: 0x7ffff7abf18b (<__GI_raise+203>:	mov    rax,QWORD PTR [rsp+0x108])
RDX: 0x0 
RSI: 0x7fffffffd8c0 --> 0x0 
RDI: 0x2 
RBP: 0x7ffff7f5b182 ("std::bad_alloc")
RSP: 0x7fffffffd8c0 --> 0x0 
RIP: 0x7ffff7abf18b (<__GI_raise+203>:	mov    rax,QWORD PTR [rsp+0x108])
R8 : 0x0 
R9 : 0x7fffffffd8c0 --> 0x0 
R10: 0x8 
R11: 0x246 
R12: 0x55555565c8f0 --> 0x0 
R13: 0x7ffff7e7da60 (<_ZNSt9bad_allocD2Ev>:	endbr64)
R14: 0x0 
R15: 0x0
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x7ffff7abf17f <__GI_raise+191>:	mov    edi,0x2
   0x7ffff7abf184 <__GI_raise+196>:	mov    eax,0xe
   0x7ffff7abf189 <__GI_raise+201>:	syscall 
=> 0x7ffff7abf18b <__GI_raise+203>:	mov    rax,QWORD PTR [rsp+0x108]
   0x7ffff7abf193 <__GI_raise+211>:	xor    rax,QWORD PTR fs:0x28
   0x7ffff7abf19c <__GI_raise+220>:	jne    0x7ffff7abf1c4 <__GI_raise+260>
   0x7ffff7abf19e <__GI_raise+222>:	mov    eax,r8d
   0x7ffff7abf1a1 <__GI_raise+225>:	add    rsp,0x118
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffd8c0 --> 0x0 
0008| 0x7fffffffd8c8 --> 0x0 
0016| 0x7fffffffd8d0 --> 0x0 
0024| 0x7fffffffd8d8 --> 0x0 
0032| 0x7fffffffd8e0 --> 0x0 
0040| 0x7fffffffd8e8 --> 0x0 
0048| 0x7fffffffd8f0 ("std::bad_alloc")
0056| 0x7fffffffd8f8 --> 0x636f6c6c615f ('_alloc')
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGABRT
__GI_raise (sig=sig@entry=0x6) at ../sysdeps/unix/sysv/linux/raise.c:50
50	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

```
overflow of Ap4Array.h in function EnsureCapacity
This is a GitHub Issue
repo:Bento4
owner:axiomatic-systems
Title : overflow of Ap4Array.h in function EnsureCapacity
Issue date:

--- start body ---
overflow of Ap4Array.h in function EnsureCapacity

Hi
I found an crash erro.

System info：
Ubuntu 20.04 : clang 10.0.0 , gcc 9.3.0

Bento4 version 1.6.0.0

commit:0c7705733de80172712e487dd6fdd28387fd7184

[poc.zip](https://github.com/axiomatic-systems/Bento4/files/6469891/poc5.zip)

------------------------------------------
Verification steps：
1.Get the source code of Bento4
2.Compile the Bento4

```bash
$ cd Bento4
$ mkdir check_build && cd check_build
$ cmake ../ -DCMAKE_C_COMPILER=clang  -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="-fsanitize=address" -DCMAKE_CXX_FLAGS="-fsanitize=address"
$ make -j 32
```

3.run mp4tag
```bash
$ ./mp4tag poc  
```

asan info
```bash
=================================================================
==4151181==ERROR: AddressSanitizer: allocator is out of memory trying to allocate 0x6d6574610 bytes
    #0 0x4c48fd in operator new(unsigned long) (/home/hh/Downloads/Bento4/target/mp4tag+0x4c48fd)
    #1 0x61752f in AP4_Array<AP4_TrunAtom::Entry>::EnsureCapacity(unsigned int) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4Array.h:172:25
    #2 0x61752f in AP4_Array<AP4_TrunAtom::Entry>::SetItemCount(unsigned int) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4Array.h:210:25
    #3 0x61752f in AP4_TrunAtom::AP4_TrunAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4TrunAtom.cpp:127:15
    #4 0x616bca in AP4_TrunAtom::Create(unsigned int, AP4_ByteStream&) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4TrunAtom.cpp:51:16
    #5 0x4e0f81 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&, unsigned int, unsigned int, unsigned long long, AP4_Atom*&) /home/hh/Downloads/Bento4/Source/C++/Core/Ap4AtomFactory.cpp:429:20

==4151181==HINT: if you don't care about these errors you may set allocator_may_return_null=1
SUMMARY: AddressSanitizer: out-of-memory (/home/hh/Downloads/Bento4/target/mp4tag+0x4c48fd) in operator new(unsigned long)
==4151181==ABORTING
```

gdb info
```bash
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Program received signal SIGABRT, Aborted.
[----------------------------------registers-----------------------------------]
RAX: 0x0 
RBX: 0x7ffff7a77f40 (0x00007ffff7a77f40)
RCX: 0x7ffff7abf18b (<__GI_raise+203>:	mov    rax,QWORD PTR [rsp+0x108])
RDX: 0x0 
RSI: 0x7fffffffd8c0 --> 0x0 
RDI: 0x2 
RBP: 0x7ffff7f5b182 ("std::bad_alloc")
RSP: 0x7fffffffd8c0 --> 0x0 
RIP: 0x7ffff7abf18b (<__GI_raise+203>:	mov    rax,QWORD PTR [rsp+0x108])
R8 : 0x0 
R9 : 0x7fffffffd8c0 --> 0x0 
R10: 0x8 
R11: 0x246 
R12: 0x55555565c8f0 --> 0x0 
R13: 0x7ffff7e7da60 (<_ZNSt9bad_allocD2Ev>:	endbr64)
R14: 0x0 
R15: 0x0
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x7ffff7abf17f <__GI_raise+191>:	mov    edi,0x2
   0x7ffff7abf184 <__GI_raise+196>:	mov    eax,0xe
   0x7ffff7abf189 <__GI_raise+201>:	syscall 
=> 0x7ffff7abf18b <__GI_raise+203>:	mov    rax,QWORD PTR [rsp+0x108]
   0x7ffff7abf193 <__GI_raise+211>:	xor    rax,QWORD PTR fs:0x28
   0x7ffff7abf19c <__GI_raise+220>:	jne    0x7ffff7abf1c4 <__GI_raise+260>
   0x7ffff7abf19e <__GI_raise+222>:	mov    eax,r8d
   0x7ffff7abf1a1 <__GI_raise+225>:	add    rsp,0x118
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffd8c0 --> 0x0 
0008| 0x7fffffffd8c8 --> 0x0 
0016| 0x7fffffffd8d0 --> 0x0 
0024| 0x7fffffffd8d8 --> 0x0 
0032| 0x7fffffffd8e0 --> 0x0 
0040| 0x7fffffffd8e8 --> 0x0 
0048| 0x7fffffffd8f0 ("std::bad_alloc")
0056| 0x7fffffffd8f8 --> 0x636f6c6c615f ('_alloc')
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGABRT
__GI_raise (sig=sig@entry=0x6) at ../sysdeps/unix/sysv/linux/raise.c:50
50	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

```
--- end body ---

The issue in Bento4's Ap4Array.h in the EnsureCapacity function indicates a potential vulnerability related to memory allocation. The crash occurs due to an attempt to allocate an excessively large amount of memory, leading to a std::bad_alloc exception. This could be exploited to cause a Denial of Service (DoS) by providing specially crafted input that triggers this behavior.