Heap out of bounds read in DrawDashPolygon()
Swiss army knife of image processing
Brought to you by:
bfriesen
After some fuzz testing I found a crashing test case.
Changeset: 15133:198ea602ea7c
Command: gm convert -negate -clip gm_hoobr_DrawDashPolygon /dev/null
ASAN Context:
==1957==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000000238 at pc 0x000000697152 bp 0x7ffce86e36f0 sp 0x7ffce86e36e8
READ of size 8 at 0x603000000238 thread T0
#0 0x697151 in DrawDashPolygon XYZ/GM/magick/render.c
#1 0x697151 in DrawPrimitive XYZ/GM/magick/render.c:4541
#2 0x697151 in DrawImage XYZ/GM/magick/render.c:3409
#3 0x81ddd2 in ReadMVGImage XYZ/GM/coders/mvg.c:195:10
#4 0x595019 in ReadImage XYZ/GM/magick/constitute.c:1607:13
#5 0x8b8e40 in ReadSVGImage XYZ/GM/coders/svg.c:3021:13
#6 0x595019 in ReadImage XYZ/GM/magick/constitute.c:1607:13
#7 0x51a1c0 in ConvertImageCommand XYZ/GM/magick/command.c:4348:22
#8 0x52fcf1 in MagickCommand XYZ/GM/magick/command.c:8869:17
#9 0x567933 in GMCommandSingle XYZ/GM/magick/command.c:17396:10
#10 0x566633 in GMCommand XYZ/GM/magick/command.c:17449:16
#11 0x7fcb56f5882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#12 0x41beb8 in _start (/usr/local/bin/gm+0x41beb8)
0x603000000238 is located 0 bytes to the right of 24-byte region [0x603000000220,0x603000000238)
allocated by thread T0 here:
#0 0x4c2bbc in __interceptor_malloc /scratch/llvm/clang-4/xenial/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:66:3
#1 0x61e596 in MagickMalloc XYZ/GM/magick/memory.c:156:10
#2 0x61e596 in MagickMallocArray XYZ/GM/magick/memory.c:347
#3 0x81ddd2 in ReadMVGImage XYZ/GM/coders/mvg.c:195:10
#4 0x595019 in ReadImage XYZ/GM/magick/constitute.c:1607:13
#5 0x8b8e40 in ReadSVGImage XYZ/GM/coders/svg.c:3021:13
#6 0x595019 in ReadImage XYZ/GM/magick/constitute.c:1607:13
#7 0x51a1c0 in ConvertImageCommand XYZ/GM/magick/command.c:4348:22
#8 0x52fcf1 in MagickCommand XYZ/GM/magick/command.c:8869:17
#9 0x567933 in GMCommandSingle XYZ/GM/magick/command.c:17396:10
#10 0x566633 in GMCommand XYZ/GM/magick/command.c:17449:16
#11 0x7fcb56f5882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
SUMMARY: AddressSanitizer: heap-buffer-overflow XYZ/GM/magick/render.c in DrawDashPolygon
Shadow bytes around the buggy address:
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 00 00 fa fa 00 00
0x0c067fff8010: 05 fa fa fa fd fd fd fd fa fa 00 00 00 02 fa fa
0x0c067fff8020: fd fd fd fd fa fa fd fd fd fa fa fa fd fd fd fd
0x0c067fff8030: fa fa fd fd fd fa fa fa fd fd fd fd fa fa 00 00
=>0x0c067fff8040: 00 fa fa fa 00 00 00[fa]fa fa fd fd fd fa fa fa
0x0c067fff8050: fd fd fd fa fa fa fd fd fd fd fa fa 00 00 00 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
0x0c067fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c067fff8090: 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
==1957==ABORTING
This problem is fixed by Mercurial changeset 15163:2835184bfb78. Thanks for reporting the issue.