Hi, there.

There is a reachable assertion failure in mp4fragment,  Ap4Atom.cpp:763, in the newest commit 5b7cc250. This issue seems to be an incomplete fix of issues #197, #351, and #547. It is related to issue #777 but has a different reproducing way.

To reproduce, run:
~~~~
./mp4fragment poc /dev/null
~~~~

Here is the trace reported by ASAN:
~~~~
==1783207==ERROR: AddressSanitizer: ABRT on unknown address 0x03ea001b35a7 (pc 0x7f1579cfe00b bp 0x7f1579e73588 sp 0x7ffff0b21170 T0)
     #0 0x7f1579cfe00b in raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
     #1 0x7f1579cdd858 in abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:79:7
     #2 0x7f1579cdd728 in __assert_fail_base /build/glibc-SzIz7B/glibc-2.31/assert/assert.c:92:3
     #3 0x7f1579ceefd5 in __assert_fail /build/glibc-SzIz7B/glibc-2.31/assert/assert.c:101:3
     #4 0x5153f0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:763:5
     #5 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #6 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #7 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #8 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #9 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #10 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #11 0x5dfac2 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #12 0x5dfac2 in AP4_SampleEntry::Write(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4SampleEntry.cpp:176:23
     #13 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #14 0x600622 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #15 0x600622 in AP4_StsdAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4StsdAtom.cpp:144:23
     #16 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #17 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #18 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #19 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #20 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #21 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #22 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #23 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #24 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #25 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #26 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #27 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #28 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #29 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #30 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #31 0x507e23 in Fragment(AP4_File&, AP4_ByteStream&, AP4_Array<TrackCursor*>&, unsigned int, unsigned int, bool, bool, bool)  /benchmark/Bento4/Source/C++/Apps/Mp4Fragment/Mp4Fragment.cpp:824:34
     #32 0x507e23 in main  /benchmark/Bento4/Source/C++/Apps/Mp4Fragment/Mp4Fragment.cpp:1475:5
     #33 0x7f1579cdf082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
     #34 0x41d8ad in _start ( /benchmark/Bento4/build-a/mp4fragment+0x41d8ad)
 
 AddressSanitizer can not provide additional info.
 SUMMARY: AddressSanitizer: ABRT /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1 in raise
 ==1783207==ABORTING
~~~~

[mp4fragment_assertion_Ap4Atom.cpp763.zip](https://github.com/axiomatic-systems/Bento4/files/9817360/mp4fragment_assertion_Ap4Atom.cpp763.zip)
(unzip first)
Assertion Failure in mp4fragment, Ap4Atom.cpp:763
This is a GitHub Issue
repo:Bento4
owner:axiomatic-systems
Title : Assertion Failure in mp4fragment, Ap4Atom.cpp:763
Issue date:

--- start body ---
Hi, there.

There is a reachable assertion failure in mp4fragment,  Ap4Atom.cpp:763, in the newest commit 5b7cc250. This issue seems to be an incomplete fix of issues #197, #351, and #547. It is related to issue #777 but has a different reproducing way.

To reproduce, run:
~~~~
./mp4fragment poc /dev/null
~~~~

Here is the trace reported by ASAN:
~~~~
==1783207==ERROR: AddressSanitizer: ABRT on unknown address 0x03ea001b35a7 (pc 0x7f1579cfe00b bp 0x7f1579e73588 sp 0x7ffff0b21170 T0)
     #0 0x7f1579cfe00b in raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
     #1 0x7f1579cdd858 in abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:79:7
     #2 0x7f1579cdd728 in __assert_fail_base /build/glibc-SzIz7B/glibc-2.31/assert/assert.c:92:3
     #3 0x7f1579ceefd5 in __assert_fail /build/glibc-SzIz7B/glibc-2.31/assert/assert.c:101:3
     #4 0x5153f0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:763:5
     #5 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #6 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #7 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #8 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #9 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #10 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #11 0x5dfac2 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #12 0x5dfac2 in AP4_SampleEntry::Write(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4SampleEntry.cpp:176:23
     #13 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #14 0x600622 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #15 0x600622 in AP4_StsdAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4StsdAtom.cpp:144:23
     #16 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #17 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #18 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #19 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #20 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #21 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #22 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #23 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #24 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #25 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #26 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #27 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #28 0x514ff0 in AP4_AtomListWriter::Action(AP4_Atom*) const  /benchmark/Bento4/Source/C++/Core/Ap4Atom.cpp:757:11
     #29 0x540f21 in AP4_List<AP4_Atom>::Apply(AP4_List<AP4_Atom>::Item::Operator const&) const  /benchmark/Bento4/Source/C++/Core/Ap4List.h:353:12
     #30 0x540f21 in AP4_ContainerAtom::WriteFields(AP4_ByteStream&)  /benchmark/Bento4/Source/C++/Core/Ap4ContainerAtom.cpp:232:23
     #31 0x507e23 in Fragment(AP4_File&, AP4_ByteStream&, AP4_Array<TrackCursor*>&, unsigned int, unsigned int, bool, bool, bool)  /benchmark/Bento4/Source/C++/Apps/Mp4Fragment/Mp4Fragment.cpp:824:34
     #32 0x507e23 in main  /benchmark/Bento4/Source/C++/Apps/Mp4Fragment/Mp4Fragment.cpp:1475:5
     #33 0x7f1579cdf082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
     #34 0x41d8ad in _start ( /benchmark/Bento4/build-a/mp4fragment+0x41d8ad)
 
 AddressSanitizer can not provide additional info.
 SUMMARY: AddressSanitizer: ABRT /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1 in raise
 ==1783207==ABORTING
~~~~

[mp4fragment_assertion_Ap4Atom.cpp763.zip](https://github.com/axiomatic-systems/Bento4/files/9817360/mp4fragment_assertion_Ap4Atom.cpp763.zip)
(unzip first)
--- end body ---

An assertion failure in the mp4fragment tool of Bento4 at Ap4Atom.cpp:763 can lead to a Denial of Service (DoS) when processing certain input files. This issue is related to previous issues and indicates that the software does not handle specific cases correctly, resulting in a crash instead of a graceful error message.