{"id":602,"date":"2016-09-22T14:35:08","date_gmt":"2016-09-22T12:35:08","guid":{"rendered":"http:\/\/blogs.gentoo.org\/ago\/?p=602"},"modified":"2016-12-01T15:51:06","modified_gmt":"2016-12-01T13:51:06","slug":"mupdf-mutool-infinite-loop-in-gatherresourceinfo-pdfinfo-c","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/ago\/2016\/09\/22\/mupdf-mutool-infinite-loop-in-gatherresourceinfo-pdfinfo-c\/","title":{"rendered":"mupdf: mutool: infinite loop in gatherresourceinfo (pdfinfo.c)"},"content":{"rendered":"<p><strong>Description<\/strong>:<br \/>\n<a href=\"http:\/\/mupdf.com\/\">mupdf<\/a> is a lightweight PDF viewer and toolkit written in portable C.<\/p>\n<p>A fuzzing through mutool revealed an infinite loop in gatherresourceinfo if mutool tries to get info from a crafted pdf.<\/p>\n<p>The output is a bit cutted because the original is ~1300 lines (because of the loop)<\/p>\n<pre><font size=\"2\"># mutool info $FILE\r\n[cut here]\r\nwarning: not a font dict (0 0 R)\r\nASAN:DEADLYSIGNAL\r\n=================================================================\r\n==8763==ERROR: AddressSanitizer: stack-overflow on address 0x7ffeb34e6f6c (pc 0x7f188e685b2e bp 0x7ffeb34e7410 sp 0x7ffeb34e6ea0 T0)\r\n    #0 0x7f188e685b2d in _IO_vfprintf \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/stdio-common\/vfprintf.c:1266\r\n    #1 0x7f188e6888c0 in buffered_vfprintf \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/stdio-common\/vfprintf.c:2346\r\n    #2 0x7f188e685cd4 in _IO_vfprintf \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/stdio-common\/vfprintf.c:1292\r\n    #3 0x49927f in __interceptor_vfprintf \/var\/tmp\/portage\/sys-devel\/llvm-3.8.0-r3\/work\/llvm-3.8.0.src\/projects\/compiler-rt\/lib\/asan\/..\/sanitizer_common\/sanitizer_common_interceptors.inc:1111\r\n    #4 0x499352 in fprintf \/var\/tmp\/portage\/sys-devel\/llvm-3.8.0-r3\/work\/llvm-3.8.0.src\/projects\/compiler-rt\/lib\/asan\/..\/sanitizer_common\/sanitizer_common_interceptors.inc:1156\r\n    #5 0x7f188f70f03c in fz_flush_warnings \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/fitz\/error.c:18:3\r\n    #6 0x7f188f70f03c in fz_throw \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/fitz\/error.c:168\r\n    #7 0x7f188fac98d5 in pdf_parse_ind_obj \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/pdf\/pdf-parse.c:565:3\r\n    #8 0x7f188fb5fe6b in pdf_cache_object \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/pdf\/pdf-xref.c:2029:13\r\n    #9 0x7f188fb658d2 in pdf_resolve_indirect \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/pdf\/pdf-xref.c:2155:12\r\n    #10 0x7f188fbc0a0d in pdf_is_dict \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/pdf\/pdf-object.c:268:2\r\n    #11 0x53ea6a in gatherfonts \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/tools\/pdfinfo.c:257:8\r\n    #12 0x53ea6a in gatherresourceinfo \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/tools\/pdfinfo.c:595\r\n    #13 0x53f31b in gatherresourceinfo \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/tools\/pdfinfo.c:603:5\r\n    [cut here]\r\n    #253 0x53f31b in gatherresourceinfo \/var\/tmp\/portage\/app-text\/mupdf-1.9a\/work\/mupdf-1.9a\/source\/tools\/pdfinfo.c:603:5\r\n\r\nSUMMARY: AddressSanitizer: stack-overflow \/var\/tmp\/portage\/sys-libs\/glibc-2.22-r4\/work\/glibc-2.22\/stdio-common\/vfprintf.c:1266 in _IO_vfprintf\r\n==8763==ABORTING\r\n1152.crashes:\r\nPDF-1.4\r\nPages: 1\r\nRetrieving info from pages 1-1...\r\n<\/font><\/pre>\n<p><strong>Affected version:<\/strong><br \/>\n1.9a<\/p>\n<p><strong>Fixed version:<\/strong><br \/>\n1.10<\/p>\n<p><strong>Commit fix:<\/strong><br \/>\n<a href=\"http:\/\/git.ghostscript.com\/?p=mupdf.git;h=fdf71862fe929b4560e9f632d775c50313d6ef02\">http:\/\/git.ghostscript.com\/?p=mupdf.git;h=fdf71862fe929b4560e9f632d775c50313d6ef02<\/a><\/p>\n<p><strong>Credit:<\/strong><br \/>\nThis bug was discovered by Agostino Sarubbo of Gentoo.<\/p>\n<p><strong>Timeline:<\/strong><br \/>\n2016-08-05: bug discovered<br \/>\n2016-08-05: bug reported to upstream<br \/>\n2016-09-22: upstream released a patch<br \/>\n2016-09-22: blog post about the issue<br \/>\n2016-10-21: upstream released 1.10<\/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=\"JyjF2aDS4M\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/blogs.gentoo.org\/ago\/2016\/09\/22\/mupdf-mutool-infinite-loop-in-gatherresourceinfo-pdfinfo-c\/\">mupdf: mutool: infinite loop in gatherresourceinfo (pdfinfo.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\/09\/22\/mupdf-mutool-infinite-loop-in-gatherresourceinfo-pdfinfo-c\/embed\/#?secret=JyjF2aDS4M\" data-secret=\"JyjF2aDS4M\" width=\"600\" height=\"338\" title=\"&#8220;mupdf: mutool: infinite loop in gatherresourceinfo (pdfinfo.c)&#8221; &#8212; agostino&#039;s blog\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: mupdf is a lightweight PDF viewer and toolkit written in portable C. A fuzzing through mutool revealed an infinite loop in gatherresourceinfo if mutool tries to get info from a crafted pdf. The output is a bit cutted because &hellip; <a href=\"https:\/\/blogs.gentoo.org\/ago\/2016\/09\/22\/mupdf-mutool-infinite-loop-in-gatherresourceinfo-pdfinfo-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-9I","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/602"}],"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=602"}],"version-history":[{"count":8,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/602\/revisions"}],"predecessor-version":[{"id":988,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/posts\/602\/revisions\/988"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/media?parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/categories?post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/ago\/wp-json\/wp\/v2\/tags?post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}