{"id":1009,"date":"2016-12-01T17:49:38","date_gmt":"2016-12-01T15:49:38","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1009"},"modified":"2017-04-29T15:44:25","modified_gmt":"2017-04-29T13:44:25","slug":"libming-listswf-heap-based-buffer-overflow-in-parseswf_rgba-parser-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2016\/12\/01\/libming-listswf-heap-based-buffer-overflow-in-parseswf_rgba-parser-c\/","title":{"rendered":"libming: listswf: heap-based buffer overflow in parseSWF_RGBA (parser.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/www.libming.org\">libming<\/a> is a Flash (SWF) output library. It can be used from PHP, Perl, Ruby, Python, C, C++, Java, and probably more on the way..<\/p>\n<p>A fuzzing revealed an overflow in listswf. The bug does not reside in any shared object but if you have a web application that calls directly the listswf binary to parse untrusted swf, then you are affected.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><font size=\"2\"># listswf $FILE\r\nheader indicates a filesize of 237 but filesize is 191\r\nFile version: 6\r\nFile size: 191\r\nFrame size: (3493,-4999)x(-5076,9541)\r\nFrame rate: 39.625000 \/ sec.\r\nTotal frames: 33032\r\n Stream out of sync after parse of blocktype 18 (SWF_SOUNDSTREAMHEAD). 29 but expecting 27.\r\n\r\nOffset: 21 (0x0015)\r\nBlock type: 18 (SWF_SOUNDSTREAMHEAD)\r\nBlock length: 4\r\n\r\n  PlaybackSoundRate 5.5 kHz\r\n  PlaybackSoundSize 16 bit\r\n  PlaybackSoundType stereo\r\n  StreamSoundCompression MP3\r\n  StreamSoundRate 44 kHz\r\n  StreamSoundSize error\r\n  StreamSoundType mono\r\n  StreamSoundSampleCount 10838\r\n  LatencySeek 53805\r\n\r\nOffset: 27 (0x001b)\r\nBlock type: 840 (Unknown Block Type)\r\nBlock length: 45\r\n\r\n\r\n0000: 2c 37 a6 30 3a 29 ab d2  54 6e 8e 88 0a f5 1b 6a    ,7.0:).. Tn.....j\r\n0010: a2 f7 a1 a3 a3 a1 e1 06  70 04 8e 90 82 03 40 47    ........ p.....@G\r\n0020: e0 30 c6 a6 83 57 ac 46  4f 8a 91 76 07             .0...W.F O..v.\r\n\r\n\r\n\r\nOffset: 74 (0x004a)\r\nBlock type: 514 (Unknown Block Type)\r\nBlock length: 27\r\n\r\n\r\n0000: b2 05 12 c2 3e 3a 01 20  d8 a7 7d 63 01 11 5c fc    ....&gt;:.  ..}c..\\.\r\n0010: 15 8e 90 43 8f 64 8e 58  49 ad 95                   ...C.d.X I..\r\n\r\n\r\n\r\nOffset: 103 (0x0067)\r\nBlock type: 297 (Unknown Block Type)\r\nBlock length: 20\r\n\r\n\r\n0000: 27 79 a2 e3 2c 56 2a 2d  d2 2c 37 a6 30 3a 29 ab    'y..,V*- .,7.0:).\r\n0010: d2 54 6e 8e                                        .Tn.\r\n\r\n\r\nskipping 8 bytes\r\n\r\nOffset: 125 (0x007d)\r\nBlock type: 42 (SWF_DEFINETEXTFORMAT)\r\nBlock length: 8\r\n\r\n255 gradients in SWF_MORPHGRADiENT, expected a max of 8=================================================================\r\n==31250==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62400000df10 at pc 0x00000057f342 bp 0x7ffe24b21ef0 sp 0x7ffe24b21ee8\r\nWRITE of size 1 at 0x62400000df10 thread T0\r\n    #0 0x57f341 in parseSWF_RGBA \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:66:12\r\n    #1 0x57f341 in parseSWF_MORPHGRADIENTRECORD \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:746\r\n    #2 0x57f341 in parseSWF_MORPHGRADIENT \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:761\r\n    #3 0x57e25a in parseSWF_MORPHFILLSTYLE \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:777:7\r\n    #4 0x58b9b8 in parseSWF_MORPHFILLSTYLES \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:804:7\r\n    #5 0x58b9b8 in parseSWF_DEFINEMORPHSHAPE \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:2098\r\n    #6 0x5302cb in blockParse \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/blocktypes.c:145:14\r\n    #7 0x527d4f in readMovie \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/main.c:265:11\r\n    #8 0x527d4f in main \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/main.c:350\r\n    #9 0x7f39cc7da61f in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/csu\/libc-start.c:289\r\n    #10 0x419b38 in _init (\/usr\/bin\/listswf+0x419b38)\r\n\r\n0x62400000df10 is located 0 bytes to the right of 7696-byte region [0x62400000c100,0x62400000df10)\r\nallocated by thread T0 here:\r\n    #0 0x4d2af5 in calloc \/tmp\/portage\/sys-devel\/llvm-3.9.0-r1\/work\/llvm-3.9.0.src\/projects\/compiler-rt\/lib\/asan\/asan_malloc_linux.cc:72\r\n    #1 0x58b90a in parseSWF_MORPHFILLSTYLES \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:801:28\r\n    #2 0x58b90a in parseSWF_DEFINEMORPHSHAPE \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:2098\r\n    #3 0x5302cb in blockParse \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/blocktypes.c:145:14\r\n    #4 0x527d4f in readMovie \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/main.c:265:11\r\n    #5 0x527d4f in main \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/main.c:350\r\n    #6 0x7f39cc7da61f in __libc_start_main \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/csu\/libc-start.c:289\r\n\r\nSUMMARY: AddressSanitizer: heap-buffer-overflow \/tmp\/portage\/media-libs\/ming-0.4.7\/work\/ming-0_4_7\/util\/parser.c:66:12 in parseSWF_RGBA\r\nShadow bytes around the buggy address:\r\n  0x0c487fff9b90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c487fff9ba0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c487fff9bb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c487fff9bc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c487fff9bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n=&gt;0x0c487fff9be0: 00 00[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c487fff9bf0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c487fff9c00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c487fff9c10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c487fff9c20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c487fff9c30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\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  Heap right redzone:      fb\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 partial redzone:   f4\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==31250==ABORTING\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n0.4.7<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n0.4.8<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/libming\/libming\/commit\/94b25ed1b038b5392fdaa6b845f6f501aba54130\">https:\/\/github.com\/libming\/libming\/commit\/94b25ed1b038b5392fdaa6b845f6f501aba54130<\/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-2016-9831<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00076-libming-heapoverflow-parseSWF_RGBA\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00076-libming-heapoverflow-parseSWF_RGBA<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2016-11-24: bug discovered and reported to upstream<br \/>\n2016-12-01: blog post about the issue<br \/>\n2016-12-05: CVE assigned<br \/>\n2017-01-30: upstream released a patch<br \/>\n2017-04-07: upstream released 0.4.8<\/p>\n<p><strong>Note:<\/strong><br \/>\nThis bug was found with <a href=\"http:\/\/lcamtuf.coredump.cx\/afl\">American Fuzzy Lop<\/a>.<\/p>\n<p><strong>Permalink:<\/strong><\/p>\n<blockquote data-secret=\"UDnzZButC6\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2016\/12\/01\/libming-listswf-heap-based-buffer-overflow-in-parseswf_rgba-parser-c\/\">libming: listswf: heap-based buffer overflow in parseSWF_RGBA (parser.c)<\/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\/2016\/12\/01\/libming-listswf-heap-based-buffer-overflow-in-parseswf_rgba-parser-c\/embed\/#?secret=UDnzZButC6\" data-secret=\"UDnzZButC6\" width=\"600\" height=\"338\" title=\"&#8220;libming: listswf: heap-based buffer overflow in parseSWF_RGBA (parser.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: libming is a Flash (SWF) output library. It can be used from PHP, Perl, Ruby, Python, C, C++, Java, and probably more on the way.. A fuzzing revealed an overflow in listswf. The bug does not reside in any &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2016\/12\/01\/libming-listswf-heap-based-buffer-overflow-in-parseswf_rgba-parser-c\/\">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-gh","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1009"}],"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=1009"}],"version-history":[{"count":8,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1009\/revisions"}],"predecessor-version":[{"id":1690,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1009\/revisions\/1690"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}