heap buffer overflow in GetStyleTokens
Swiss army knife of image processing
Brought to you by:
bfriesen
On GraphicsMagick 1.3.26 2017-07-04 Q8
A heap buffer overflow vulnerability was found in function GetStyleTokens,which allow attackers to cause a denial of service via a crafted file.
#./gm identify $FILE
=================================================================
==119271==ERROR: heap-buffer-overflow on address 0x603000000120 at pc 0x000000d8d76e bp 0x7fff02f0c0d0 sp 0x7fff02f0c0c8
WRITE of size 8 at 0x603000000120 thread T0
#0 0xd8d76d in GetStyleTokens /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:314:12
#1 0xd8d76d in SVGStartElement /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:1666
#2 0x7fb9d99ecce4 in xmlParseStartTag (/lib64/libxml2.so.2+0x42ce4)
#3 0x7fb9d99fa632 (/lib64/libxml2.so.2+0x50632)
#4 0x7fb9d99fb61d in xmlParseChunk (/lib64/libxml2.so.2+0x5161d)
#5 0xd7cb30 in ReadSVGImage /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:2959:14
#6 0x63f90d in ReadImage /home/test/Downloads/GraphicsMagick-1.3.26/magick/constitute.c:1607:13
#7 0x63ed64 in PingImage /home/test/Downloads/GraphicsMagick-1.3.26/magick/constitute.c:1370:9
#8 0x5ab160 in IdentifyImageCommand /home/test/Downloads/GraphicsMagick-1.3.26/magick/command.c:8379:17
#9 0x5b0232 in MagickCommand /home/test/Downloads/GraphicsMagick-1.3.26/magick/command.c:8869:17
#10 0x5f621e in GMCommandSingle /home/test/Downloads/GraphicsMagick-1.3.26/magick/command.c:17396:10
#11 0x5f4aab in GMCommand /home/test/Downloads/GraphicsMagick-1.3.26/magick/command.c:17449:16
#12 0x7fb9d88b4b34 in __libc_start_main /usr/src/debug/glibc-2.17-c758a686/csu/../csu/libc-start.c:274
#13 0x4247fb in _start (/home/test/Downloads/IM-GM-build/bin/gm+0x4247fb)
0x603000000120 is located 0 bytes to the right of 32-byte region [0x603000000100,0x603000000120)
allocated by thread T0 here:
#0 0x4e96f6 in __interceptor_malloc /home/test/Downloads/llvm-clang/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:66
#1 0xd885f9 in GetStyleTokens /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:290:10
#2 0xd885f9 in SVGStartElement /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:1666
#3 0x7fb9d99ecce4 in xmlParseStartTag (/lib64/libxml2.so.2+0x42ce4)
heap-buffer-overflow /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:314:12 in GetStyleTokens
Shadow bytes around the buggy address:
0x0c067fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c067fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c067fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c067fff8000: fa fa fd fd fd fd fa fa 00 00 04 fa fa fa 00 00
0x0c067fff8010: 00 00 fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa
=>0x0c067fff8020: 00 00 00 00[fa]fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
The poc file is in the attachment.
Credit: ADLab of Venustech
Fixed by Mercurial changeset 15121:54f48ab2d52a.
Please use CVE-2017-13063 for this issue.