{"id":1542,"date":"2017-03-31T16:47:08","date_gmt":"2017-03-31T14:47:08","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=1542"},"modified":"2017-04-01T16:18:40","modified_gmt":"2017-04-01T14:18:40","slug":"podofo-heap-based-buffer-overflow-in-podofopdfsimpleencodingconverttoencoding-pdfencoding-cpp","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2017\/03\/31\/podofo-heap-based-buffer-overflow-in-podofopdfsimpleencodingconverttoencoding-pdfencoding-cpp\/","title":{"rendered":"podofo: heap-based buffer overflow in PoDoFo::PdfSimpleEncoding::ConvertToEncoding (PdfEncoding.cpp)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"https:\/\/sourceforge.net\/projects\/podofo\/\">podofo<\/a> is a C++ library to work with the PDF file format.<\/p>\n<p>A fuzz on it through the podofotxt2pdf command line tool reavealed an heap overflow. This post will be forwarded on the upstream mailing list.<\/p>\n<p>The complete ASan output:<\/p>\n<pre><span style=\"font-size: small\"># podofotxt2pdf $FILE out.pdf\r\n==12895==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6310000c47ff at pc 0x7f7434e576ea bp 0x7ffde7868b70 sp 0x7ffde7868b68\r\nREAD of size 1 at 0x6310000c47ff thread T0\r\n    #0 0x7f7434e576e9 in PoDoFo::PdfSimpleEncoding::ConvertToEncoding(PoDoFo::PdfString const&amp;, PoDoFo::PdfFont const*) const \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/base\/PdfEncoding.cpp:484:21\r\n    #1 0x7f7435337c7f in PoDoFo::PdfFont::WriteStringToStream(PoDoFo::PdfString const&amp;, PoDoFo::PdfStream*) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/doc\/PdfFont.cpp:144:47\r\n    #2 0x7f74356a5374 in PoDoFo::PdfPainter::DrawText(double, double, PoDoFo::PdfString const&amp;, long) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/doc\/PdfPainter.cpp:824:14\r\n    #3 0x519755 in draw(char*, PoDoFo::PdfDocument*, bool, char const*) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/tools\/podofotxt2pdf\/podofotxt2pdf.cpp:94:25\r\n    #4 0x51aa52 in init(char const*, char const*, bool, char const*) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/tools\/podofotxt2pdf\/podofotxt2pdf.cpp:165:5\r\n    #5 0x51c253 in main \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/tools\/podofotxt2pdf\/podofotxt2pdf.cpp:212:7\r\n    #6 0x7f743363f78f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n    #7 0x41ccb8 in _start (\/usr\/bin\/podofotxt2pdf+0x41ccb8)\r\n\r\n0x6310000c47ff is located 0 bytes to the right of 65535-byte region [0x6310000b4800,0x6310000c47ff)\r\nallocated by thread T0 here:\r\n    #0 0x4dc585 in calloc \/tmp\/portage\/sys-libs\/compiler-rt-sanitizers-4.0.0\/work\/compiler-rt-4.0.0.src\/lib\/asan\/asan_malloc_linux.cc:74\r\n    #1 0x7f7434f9f978 in PoDoFo::podofo_calloc(unsigned long, unsigned long) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/base\/PdfMemoryManagement.cpp:136:9\r\n    #2 0x7f7434e51913 in PoDoFo::PdfSimpleEncoding::InitEncodingTable() \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/base\/PdfEncoding.cpp:370:47\r\n    #3 0x7f7434e55af1 in PoDoFo::PdfSimpleEncoding::ConvertToEncoding(PoDoFo::PdfString const&amp;, PoDoFo::PdfFont const*) const \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/base\/PdfEncoding.cpp:459:51\r\n    #4 0x7f7435337c7f in PoDoFo::PdfFont::WriteStringToStream(PoDoFo::PdfString const&amp;, PoDoFo::PdfStream*) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/doc\/PdfFont.cpp:144:47\r\n    #5 0x7f74356a5374 in PoDoFo::PdfPainter::DrawText(double, double, PoDoFo::PdfString const&amp;, long) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/doc\/PdfPainter.cpp:824:14\r\n    #6 0x519755 in draw(char*, PoDoFo::PdfDocument*, bool, char const*) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/tools\/podofotxt2pdf\/podofotxt2pdf.cpp:94:25\r\n    #7 0x51aa52 in init(char const*, char const*, bool, char const*) \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/tools\/podofotxt2pdf\/podofotxt2pdf.cpp:165:5\r\n    #8 0x51c253 in main \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/tools\/podofotxt2pdf\/podofotxt2pdf.cpp:212:7\r\n    #9 0x7f743363f78f in __libc_start_main \/tmp\/portage\/sys-libs\/glibc-2.23-r3\/work\/glibc-2.23\/csu\/..\/csu\/libc-start.c:289\r\n\r\nSUMMARY: AddressSanitizer: heap-buffer-overflow \/tmp\/portage\/app-text\/podofo-0.9.5\/work\/podofo-0.9.5\/src\/base\/PdfEncoding.cpp:484:21 in PoDoFo::PdfSimpleEncoding::ConvertToEncoding(PoDoFo::PdfString const&amp;, PoDoFo::PdfFont const*) const\r\nShadow bytes around the buggy address:\r\n  0x0c62800108a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c62800108b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c62800108c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c62800108d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n  0x0c62800108e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\r\n=&gt;0x0c62800108f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00[07]\r\n  0x0c6280010900: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c6280010910: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c6280010920: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c6280010930: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\r\n  0x0c6280010940: 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  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==12895==ABORTING\r\n<\/span><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n0.9.5<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\nN\/A<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\nN\/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-7379<\/p>\n<p><strong>Reproducer:<\/strong><br \/>\n<a href=\"https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00249-podofo-heapoverflow-PdfEncoding_cpp\">https:\/\/github.com\/asarubbo\/poc\/blob\/master\/00249-podofo-heapoverflow-PdfEncoding_cpp<\/a><\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2017-03-31: bug discovered and reported to upstream<br \/>\n2017-03-31: blog post about the issue<br \/>\n2017-03-31: 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>.<\/p>\n<p><strong>Permalink:<\/strong><\/p>\n<blockquote data-secret=\"1rT7xzPnJm\" class=\"wp-embedded-content\"><p><a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/03\/31\/podofo-heap-based-buffer-overflow-in-podofopdfsimpleencodingconverttoencoding-pdfencoding-cpp\/\">podofo: heap-based buffer overflow in PoDoFo::PdfSimpleEncoding::ConvertToEncoding (PdfEncoding.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=\"https:\/\/blogs.gentoo.org\/ago\/2017\/03\/31\/podofo-heap-based-buffer-overflow-in-podofopdfsimpleencodingconverttoencoding-pdfencoding-cpp\/embed\/#?secret=1rT7xzPnJm\" data-secret=\"1rT7xzPnJm\" width=\"600\" height=\"338\" title=\"&#8220;podofo: heap-based buffer overflow in PoDoFo::PdfSimpleEncoding::ConvertToEncoding (PdfEncoding.cpp)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: podofo is a C++ library to work with the PDF file format. A fuzz on it through the podofotxt2pdf command line tool reavealed an heap overflow. This post will be forwarded on the upstream mailing list. The complete ASan &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2017\/03\/31\/podofo-heap-based-buffer-overflow-in-podofopdfsimpleencodingconverttoencoding-pdfencoding-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-oS","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1542"}],"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=1542"}],"version-history":[{"count":5,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1542\/revisions"}],"predecessor-version":[{"id":1567,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/1542\/revisions\/1567"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}