{"id":2227,"date":"2017-09-14T12:39:44","date_gmt":"2017-09-14T10:39:44","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=2227"},"modified":"2017-09-22T09:08:23","modified_gmt":"2017-09-22T07:08:23","slug":"bento4-stack-based-buffer-underflow-in-ap4_visualsampleentryreadfields-ap4sampleentry-cpp","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/09\/14\/bento4-stack-based-buffer-underflow-in-ap4_visualsampleentryreadfields-ap4sampleentry-cpp\/","title":{"rendered":"bento4: stack-based buffer underflow in AP4_VisualSampleEntry::ReadFields (Ap4SampleEntry.cpp)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"https:\/\/www.bento4.com\/\">bento4<\/a> is a fast, modern, open source C++ toolkit for all your MP4 and MPEG DASH media format needs.<\/p>\n<p>The complete ASan output of the issue:<\/p>\n<pre><font size=\"2\"># mp42aac $FILE out.aac\r\n==4435==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7fe62b800e86 at pc 0x00000057b5a3 bp 0x7ffea98c1b10 sp 0x7ffea98c1b08                                                                        \r\nWRITE of size 1 at 0x7fe62b800e86 thread T0                                                                                                                                                                       \r\n    #0 0x57b5a2 in AP4_VisualSampleEntry::ReadFields(AP4_ByteStream&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4SampleEntry.cpp:780:40                                                                             \r\n    #1 0x575726 in AP4_SampleEntry::Read(AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4SampleEntry.cpp:108:5                                                                        \r\n    #2 0x57d624 in AP4_VisualSampleEntry::AP4_VisualSampleEntry(unsigned int, unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4SampleEntry.cpp:742:5                     \r\n    #3 0x57d624 in AP4_AvcSampleEntry::AP4_AvcSampleEntry(unsigned int, unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4SampleEntry.cpp:994                             \r\n    #4 0x5cbf58 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:305:24             \r\n    #5 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14                                        \r\n    #6 0x586a2c in AP4_StsdAtom::AP4_StsdAtom(unsigned int, unsigned char, unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4StsdAtom.cpp:100:13\r\n    #7 0x58566f in AP4_StsdAtom::Create(unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4StsdAtom.cpp:56:16\r\n    #8 0x5ca71c in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:422:20\r\n    #9 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14\r\n    #10 0x60c29f in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&amp;, AP4_ByteStream&amp;, unsigned long long) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:193:12\r\n    #11 0x60b1d2 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:138:5\r\n    #12 0x60b1d2 in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:87\r\n    #13 0x5ca44c in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:751:20\r\n    #14 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14\r\n    #15 0x60c561 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&amp;, AP4_ByteStream&amp;, unsigned long long) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:193:12\r\n    #16 0x60b1d2 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:138:5\r\n    #17 0x60b1d2 in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:87\r\n    #18 0x5ca44c in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:751:20\r\n    #19 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14\r\n    #20 0x60c561 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&amp;, AP4_ByteStream&amp;, unsigned long long) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:193:12\r\n    #21 0x60b1d2 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:138:5\r\n    #22 0x60b1d2 in AP4_ContainerAtom::Create(unsigned int, unsigned long long, bool, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:87\r\n    #23 0x5ca44c in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:751:20\r\n    #24 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14\r\n    #25 0x60c561 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&amp;, AP4_ByteStream&amp;, unsigned long long) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:193:12\r\n    #26 0x60c099 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:138:5\r\n    #27 0x58e6ed in AP4_TrakAtom::AP4_TrakAtom(unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4TrakAtom.cpp:165:5\r\n    #28 0x5c8e3b in AP4_TrakAtom::Create(unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4TrakAtom.h:58:20\r\n    #29 0x5c8e3b in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:377\r\n    #30 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14\r\n    #31 0x60c561 in AP4_ContainerAtom::ReadChildren(AP4_AtomFactory&amp;, AP4_ByteStream&amp;, unsigned long long) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:193:12\r\n    #32 0x60c099 in AP4_ContainerAtom::AP4_ContainerAtom(unsigned int, unsigned long long, bool, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4ContainerAtom.cpp:138:5\r\n    #33 0x5521b0 in AP4_MoovAtom::AP4_MoovAtom(unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4MoovAtom.cpp:79:5\r\n    #34 0x5cad1d in AP4_MoovAtom::Create(unsigned int, AP4_ByteStream&amp;, AP4_AtomFactory&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4MoovAtom.h:56:20\r\n    #35 0x5cad1d in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned int, unsigned int, unsigned long long, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:357\r\n    #36 0x5c7fbd in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, unsigned long long&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:220:14\r\n    #37 0x5c75c0 in AP4_AtomFactory::CreateAtomFromStream(AP4_ByteStream&amp;, AP4_Atom*&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4AtomFactory.cpp:150:12\r\n    #38 0x54ea2c in AP4_File::ParseStream(AP4_ByteStream&amp;, AP4_AtomFactory&amp;, bool) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4File.cpp:104:12\r\n    #39 0x54f0fa in AP4_File::AP4_File(AP4_ByteStream&amp;, bool) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4File.cpp:78:5\r\n    #40 0x542552 in main \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Apps\/Mp42Aac\/Mp42Aac.cpp:242:32\r\n    #41 0x7fe62e887680 in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.23-r4\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n    #42 0x44f3f8 in _start (\/usr\/bin\/mp42aac+0x44f3f8)\r\n\r\nAddress 0x7fe62b800e86 is located in stack of thread T0 at offset 6 in frame\r\n    #0 0x57b2ef in AP4_VisualSampleEntry::ReadFields(AP4_ByteStream&amp;) \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4SampleEntry.cpp:759\r\n\r\n  This frame has 1 object(s):\r\n    [32, 65) 'compressor_name'\r\nHINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext\r\n      (longjmp and C++ exceptions *are* supported)\r\nSUMMARY: AddressSanitizer: stack-buffer-underflow \/tmp\/Bento4-1.5.0-617\/Source\/C++\/Core\/Ap4SampleEntry.cpp:780:40 in AP4_VisualSampleEntry::ReadFields(AP4_ByteStream&amp;)\r\nShadow bytes around the buggy address:\r\n  0x0ffd456f8180: f1 f1 f1 f1 00 f2 f2 f2 00 f3 f3 f3 00 00 00 00\r\n  0x0ffd456f8190: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5\r\n  0x0ffd456f81a0: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5\r\n  0x0ffd456f81b0: f1 f1 f1 f1 00 f2 f2 f2 00 f3 f3 f3 00 00 00 00\r\n  0x0ffd456f81c0: f1 f1 f1 f1 04 f2 00 f2 f2 f2 00 f3 f3 f3 f3 f3\r\n=&gt;0x0ffd456f81d0:[f1]f1 f1 f1 00 00 00 00 01 f3 f3 f3 f3 f3 f3 f3\r\n  0x0ffd456f81e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0ffd456f81f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0ffd456f8200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0ffd456f8210: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0ffd456f8220: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\nShadow byte legend (one shadow byte represents 8 application bytes):\r\n  Addressable:           00\r\n  Partially addressable: 01 02 03 04 05 06 07 \r\n  Heap left redzone:       fa\r\n  Freed heap region:       fd\r\n  Stack left redzone:      f1\r\n  Stack mid redzone:       f2\r\n  Stack right redzone:     f3\r\n  Stack after return:      f5\r\n  Stack use after scope:   f8\r\n  Global redzone:          f9\r\n  Global init order:       f6\r\n  Poisoned by user:        f7\r\n  Container overflow:      fc\r\n  Array cookie:            ac\r\n  Intra object redzone:    bb\r\n  ASan internal:           fe\r\n  Left alloca redzone:     ca\r\n  Right alloca redzone:    cb\r\n==4435==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n1.5.0-617<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\nN\/A<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/axiomatic-systems\/Bento4\/commit\/03d1222ab9c2ce779cdf01bdb96cdd69cbdcfeda\">https:\/\/github.com\/axiomatic-systems\/Bento4\/commit\/03d1222ab9c2ce779cdf01bdb96cdd69cbdcfeda<\/a><\/p>\n<p><strong>Credit:<\/strong><br \/>\nThis bug was discovered by Agostino Sarubbo of Gentoo.<\/p>\n<p><strong>CVE:<\/strong><br \/>\nCVE-2017-14639<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00344-bento4-stackunderflow-AP4_VisualSampleEntry_ReadFields\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00344-bento4-stackunderflow-AP4_VisualSampleEntry_ReadFields<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-09-08: bug discovered and reported to upstream<br \/>\n2017-09-14: blog post about the issue<br \/>\n2017-09-21: CVE assigned<\/p>\n<p><strong>Note:<\/strong><br \/>\nThis bug was found with <a href=\"http:\/\/lcamtuf.coredump.cx\/afl\">American Fuzzy Lop<\/a>.<br \/>\nThis bug was identified with bare metal servers donated by <a href=\"https:\/\/www.packet.net\/\">Packet<\/a>. This work is also supported by the <a href=\"https:\/\/www.coreinfrastructure.org\">Core Infrastructure Initiative<\/a>.<\/p>\n<p><strong>Permalink:<\/strong><\/p>\n<blockquote data-secret=\"lGSCs8oZUo\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2017\/09\/14\/bento4-stack-based-buffer-underflow-in-ap4_visualsampleentryreadfields-ap4sampleentry-cpp\/\">bento4: stack-based buffer underflow in AP4_VisualSampleEntry::ReadFields (Ap4SampleEntry.cpp)<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/blogs.gentoo.org\/ago\/2017\/09\/14\/bento4-stack-based-buffer-underflow-in-ap4_visualsampleentryreadfields-ap4sampleentry-cpp\/embed\/#?secret=lGSCs8oZUo\" data-secret=\"lGSCs8oZUo\" width=\"600\" height=\"338\" title=\"&#8220;bento4: stack-based buffer underflow in AP4_VisualSampleEntry::ReadFields (Ap4SampleEntry.cpp)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: bento4 is a fast, modern, open source C++ toolkit for all your MP4 and MPEG DASH media format needs. The complete ASan output of the issue: # mp42aac $FILE out.aac ==4435==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7fe62b800e86 at pc 0x00000057b5a3 &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/09\/14\/bento4-stack-based-buffer-underflow-in-ap4_visualsampleentryreadfields-ap4sampleentry-cpp\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":140,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[12,10],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2EaBc-zV","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2227"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/users\/140"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/comments?post=2227"}],"version-history":[{"count":4,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2227\/revisions"}],"predecessor-version":[{"id":2288,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/2227\/revisions\/2288"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=2227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=2227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=2227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}