Skip to content

heap-use-after-free at jhead/exif.c:1259 in clearOrientation() #79

@Shin-Yan

Description

@Shin-Yan

Summary

An segmentation fault caused when using jhead.
AddressSanitizer reports it as heap-use-after-free.

Version or commit

$ git log --oneline -1
4d04ac9 (HEAD -> master, tag: 3.08, origin/master, origin/HEAD) Bumped version number to 3.08

Steps to reproduce

make

$ git clone https://github.com/Matthias-Wandel/jhead.git
$ cd jhead
$ make

run

$ ./jhead -norot Poc_SQ187_jhead.jpg

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Suspicious offset of first Exif IFD value

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Illegally sized Exif subdirectory (12336 entries)

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Undefined rotation value 1291856384 in Exif

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead_test.jpg' Illegal subdirectory link in Exif header
Segmentation fault

ASAN report

$ jhead-asan/jhead -norot Poc_SQ187_jhead.jpg

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Suspicious offset of first Exif IFD value

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Illegally sized Exif subdirectory (12336 entries)

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Undefined rotation value 1291856384 in Exif

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Bad components count 30303030

Nonfatal Error : 'Poc_SQ187_jhead.jpg' Illegal subdirectory link in Exif header
=================================================================
==92528==ERROR: AddressSanitizer: heap-use-after-free on address 0x611000000a49 at pc 0x7f955a80df3d bp 0x7fff45465fd0 sp 0x7fff45465778
WRITE of size 4 at 0x611000000a49 thread T0
    #0 0x7f955a80df3c in __interceptor_memset ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:762
    #1 0x558be9cf14c3 in memset /usr/include/x86_64-linux-gnu/bits/string_fortified.h:71
    #2 0x558be9cf14c3 in ClearOrientation exif.c:1259
    #3 0x558be9ce43fe in DoAutoRotate jhead.c:750
    #4 0x558be9ce43fe in ProcessFile jhead.c:916
    #5 0x558be9ce1077 in main jhead.c:1805
    #6 0x7f955a489082 in __libc_start_main ../csu/libc-start.c:308
    #7 0x558be9ce21ed in _start (/home/fuzzer/sytseng/ASAN/jhead/jhead+0x111ed)

0x611000000a49 is located 9 bytes inside of 204-byte region [0x611000000a40,0x611000000b0c)
freed by thread T0 here:
    #0 0x7f955a8b340f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
    #1 0x558be9ce9aab in DiscardAllButExif jpgfile.c:544

previously allocated by thread T0 here:
    #0 0x7f955a8b3808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x558be9ce8407 in ReadJpegSections jpgfile.c:175
    #2 0x558be9ce8407 in ReadJpegSections jpgfile.c:118

SUMMARY: AddressSanitizer: heap-use-after-free ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:762 in __interceptor_memset
Shadow bytes around the buggy address:
  0x0c227fff80f0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c227fff8100: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c227fff8110: fd fd fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c227fff8130: 00 00 00 00 00 00 00 00 00 04 fa fa fa fa fa fa
=>0x0c227fff8140: fa fa fa fa fa fa fa fa fd[fd]fd fd fd fd fd fd
  0x0c227fff8150: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c227fff8160: fd fd fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8170: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c227fff8190: 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
  Shadow gap:              cc
==92528==ABORTING

Poc

Poc_SQ187_jhead

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions