sandyre / libopencad

OpenSource library under X/MIT license to work with CAD files (DWG/DXF). Please use repository linked below, this one is abandoned.
https://github.com/nextgis-borsch/lib_opencad
MIT License
197 stars 63 forks source link

stack-buffer-overflow in libopencad #49

Open hac425xxx opened 5 years ago

hac425xxx commented 5 years ago

AddressSanitizer Output

~/workplace/asan/libopencad/build$ ./apps/cadinfo stack-bof-opencad.dwg 
=================================================================
==165126== ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc70845dab at pc 0x47b21c bp 0x7ffc70845d50 sp 0x7ffc70845d48
WRITE of size 1 at 0x7ffc70845dab thread T0
    #0 0x47b21b (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x47b21b)
    #1 0x47c36f (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x47c36f)
    #2 0x4bae59 (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x4bae59)
    #3 0x477c9e (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x477c9e)
    #4 0x47749c (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x47749c)
    #5 0x47768d (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x47768d)
    #6 0x47426c (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x47426c)
    #7 0x7fb1d298ff44 (/lib/x86_64-linux-gnu/libc-2.19.so+0x21f44)
    #8 0x473ca8 (/home/xxx/workplace/asan/libopencad/build/apps/cadinfo+0x473ca8)
Address 0x7ffc70845dab is located at offset 43 in frame <getAsLong> of T0's stack:
  This frame has 1 object(s):
    [32, 40) 'result'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
Shadow bytes around the buggy address:
  0x10000e100b60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100b70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100b80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100b90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100ba0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10000e100bb0: f1 f1 f1 f1 00[f4]f4 f4 f3 f3 f3 f3 00 00 00 00
  0x10000e100bc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000e100c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
  Heap righ redzone:     fb
  Freed Heap region:     fd
  Stack left redzone:    f1
  Stack mid redzone:     f2
  Stack right redzone:   f3
  Stack partial redzone: f4
  Stack after return:    f5
  Stack use after scope: f8
  Global redzone:        f9
  Global init order:     f6
  Poisoned by user:      f7
  ASan internal:         fe
==165126== ABORTING

poc

https://github.com/hac425xxx/fuzzdata/blob/master/stack-bof-opencad.dwg