pts / sam2p

raster (bitmap) image converter with smart PDF and PostScript (EPS) output
http://pts.50.hu/sam2p/
GNU General Public License v2.0
42 stars 15 forks source link

heap-buffer-overflow in function ReadImage #41

Closed YourButterfly closed 6 years ago

YourButterfly commented 6 years ago

Description of problem:

There is a heap-buffer-overflow in function ReadImage,file input-tga.ci line 489. (from debug info)

Version-Release number of selected component (if applicable):

sam2p 0.49.4

The output information is as follows(with asan):

This is sam2p 0.49.4.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
sam2p: Warning: TGA:  bit image, 13 bit alpha is greater than 8 total bits per pixel
sam2p: Warning: TGA: reducing to * bit alpha: 0
sam2p: Warning: TGA: error reading; ftell == 87
=================================================================
==4587==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f96457ff580 at pc 0x7f96496cbd1a bp 0x7ffcb415fe20 sp 0x7ffcb415f5c8
WRITE of size 1554506856 at 0x7f96457ff580 thread T0
    #0 0x7f96496cbd19  (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5ed19)
    #1 0x55cd829b95f8 in ReadImage /home/pwd/fuzz/fuzz-sam2p/sam2p/input-tga.ci:489
    #2 0x55cd829b95f8 in tga_load_image(_IO_FILE*) /home/pwd/fuzz/fuzz-sam2p/sam2p/input-tga.ci:168
    #3 0x55cd829ba978 in in_tga_reader /home/pwd/fuzz/fuzz-sam2p/sam2p/in_tga.cpp:23
    #4 0x55cd82a3ddc9 in Image::load(Image::Loader::UFD*, SimBuffer::Flat const&, char const*) /home/pwd/fuzz/fuzz-sam2p/sam2p/image.cpp:1428
    #5 0x55cd82991d16 in run_sam2p_engine(Files::FILEW&, Files::FILEW&, char const* const*, bool) /home/pwd/fuzz/fuzz-sam2p/sam2p/sam2p_main.cpp:1055
    #6 0x55cd8298dd50 in main /home/pwd/fuzz/fuzz-sam2p/sam2p/sam2p_main.cpp:1148
    #7 0x7f9648f0fb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #8 0x55cd8298e9d9 in _start (/home/pwd/fuzz/fuzz-sam2p/sam2p/sam2p+0x269d9)

0x7f96457ff580 is located 0 bytes to the right of 368553344-byte region [0x7f962f884800,0x7f96457ff580)
allocated by thread T0 here:
    #0 0x7f964974bb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
    #1 0x55cd829b952c in ReadImage /home/pwd/fuzz/fuzz-sam2p/sam2p/input-tga.ci:449
    #2 0x55cd829b952c in tga_load_image(_IO_FILE*) /home/pwd/fuzz/fuzz-sam2p/sam2p/input-tga.ci:168

SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x5ed19) 
Shadow bytes around the buggy address:
  0x0ff348af7e60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff348af7e70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff348af7e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff348af7e90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff348af7ea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff348af7eb0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff348af7ec0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff348af7ed0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff348af7ee0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff348af7ef0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0ff348af7f00: 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
==4587==ABORTING

that is a breif description,i will update found by pwd@360TeamSerious

YourButterfly commented 6 years ago

POC

pts commented 6 years ago

Thank you for reporting this! Fixed it in 8b2b7151991e07ef262857c2325e95c3b2867f80.