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
=================================================================
==129128==ERROR: heap-buffer-overflow on address 0x602000000560 at pc 0x000000d8d769 bp 0x7ffd5555a7b0 sp 0x7ffd5555a7a8
WRITE of size 8 at 0x602000000560 thread T0
#0 0xd8d768 in GetStyleTokens /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:311:12
#1 0xd8d768 in SVGStartElement /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:1666
#2 0x7fb47d34ace4 in xmlParseStartTag (/lib64/libxml2.so.2+0x42ce4)
#3 0x7fb47d358632 (/lib64/libxml2.so.2+0x50632)
#4 0x7fb47d35961d 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 0x7fb47c212b34 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)
0x602000000560 is located 0 bytes to the right of 16-byte region [0x602000000550,0x602000000560)
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 0x7fb47d34ace4 in xmlParseStartTag (/lib64/libxml2.so.2+0x42ce4)
heap-buffer-overflow /home/test/Downloads/GraphicsMagick-1.3.26/coders/svg.c:311:12 in GetStyleTokens
Shadow bytes around the buggy address:
0x0c047fff8050: fa fa 00 01 fa fa 00 01 fa fa 07 fa fa fa 00 03
0x0c047fff8060: fa fa 06 fa fa fa 00 01 fa fa 05 fa fa fa fd fa
0x0c047fff8070: fa fa 00 02 fa fa 00 02 fa fa 00 01 fa fa 04 fa
0x0c047fff8080: fa fa 00 01 fa fa 02 fa fa fa 01 fa fa fa 01 fa
0x0c047fff8090: fa fa fd fd fa fa fd fa fa fa fd fa fa fa fd fa
=>0x0c047fff80a0: fa fa fd fa fa fa 02 fa fa fa 00 00[fa]fa fa fa
0x0c047fff80b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80f0: 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-13064 for this issue.