[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Heap overflow in jhead-3.03



There is a heap overflow issue in the jhead-3.03 version.

The environment is Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-93-generic x86_64).

The extra compile flag is -fsanitize=address,undefined.

Then just simple run jhead input that can trigger the overflow.

gdb memory and trace:
==13426==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61300000dfc3 at pc 0x000000448b60 bp 0x7ffe6f7703d0 sp 0x7ffe6f7703c0
READ of size 1 at 0x61300000dfc3 thread T0
    #0 0x448b5f in process_DQT /home/heqing/playground/jhead-3.03-a/jpgqguess.c:109
    #1 0x4327e9 in ReadJpegSections /home/heqing/playground/jhead-3.03-a/jpgfile.c:223
    #2 0x438676 in ReadJpegSections /home/heqing/playground/jhead-3.03-a/jpgfile.c:126
    #3 0x438676 in ReadJpegFile /home/heqing/playground/jhead-3.03-a/jpgfile.c:375
    #4 0x41dd1d in ProcessFile /home/heqing/playground/jhead-3.03-a/jhead.c:905
    #5 0x404834 in main /home/heqing/playground/jhead-3.03-a/jhead.c:1757
    #6 0x7f60ebeb582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #7 0x415de8 in _start (/home/heqing/playground/jhead-3.03-a/jhead+0x415de8)

0x61300000dfc3 is located 0 bytes to the right of 323-byte region [0x61300000de80,0x61300000dfc3)
allocated by thread T0 here:
    #0 0x7f60ed30d602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x4314e1 in ReadJpegSections /home/heqing/playground/jhead-3.03-a/jpgfile.c:173

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/heqing/playground/jhead-3.03-a/jpgqguess.c:109 process_DQT
Shadow bytes around the buggy address:
  0x0c267fff9ba0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9bb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9bc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c267fff9be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c267fff9bf0: 00 00 00 00 00 00 00 00[03]fa fa fa fa fa fa fa
  0x0c267fff9c00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9c10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9c20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9c30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c267fff9c40: 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
  Heap right 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
  Container overflow: fc
  Array cookie: ac
  Intra object redzone: bb
  ASan internal: fe
==13426==ABORTING

In gdb, it seems that the length of jpg section is not verified.
In jpgqguess.c, when handling the section info, the index a is out of bound and cause a heap overflow in the malloc array Data.

Attachment: id:000001,sig:06,src:000002,op:havoc,rep:64
Description: Binary data


Reply to: