cmft icon indicating copy to clipboard operation
cmft copied to clipboard

SEGV (ASAN: heap-buffer-overflow) on cmft::rgba8ToRgba32f

Open strongcourage opened this issue 5 years ago • 0 comments

Hi,

Our fuzzer found a crash due to a heap buffer overflow on the function cmft::rgba8ToRgba32f. I built cmft (the latest commit 06a3516 on master) using the configuration "release64" on Ubuntu 16.04 (64-bit).

PoC: https://github.com/strongcourage/PoCs/blob/master/cmft_06a3516/PoC_hbo_rgba8ToRgba32f

cmftRelease --input $PoC --output0 /dev/null
Segmentation fault

ASAN says:

cmftRelease-asan --input $PoC --output0 /dev/null
=================================================================
==22401==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000eff1 at pc 0x00000041d0b7 bp 0x7fff0e747ca0 sp 0x7fff0e747c90
READ of size 1 at 0x60200000eff1 thread T0
    #0 0x41d0b6 in cmft::rgba8ToRgba32f(float*, unsigned char const*) ../../src/cmft/image.cpp:1482
    #1 0x41d0b6 in cmft::imageToRgba32f(cmft::Image&, cmft::Image const&, cmft::AllocatorI*) ../../src/cmft/image.cpp:1671
    #2 0x420cba in cmft::imageConvert(cmft::Image&, cmft::TextureFormat::Enum, cmft::Image const&, cmft::AllocatorI*) ../../src/cmft/image.cpp:2017
    #3 0x434be1 in cmft::imageLoadStb(cmft::Image&, char const*, cmft::TextureFormat::Enum, cmft::AllocatorI*) ../../src/cmft/image.cpp:5102
    #4 0x475574 in cmftMain(int, char const* const*) ../../src/cmft_cli/cmft_cli.h:896
    #5 0x7fa6a02d082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #6 0x403608 in _start (/home/dungnguyen/PoCs/cmft_06a3516/cmftRelease-asan+0x403608)

0x60200000eff1 is located 0 bytes to the right of 1-byte region [0x60200000eff0,0x60200000eff1)
allocated by thread T0 here:
    #0 0x7fa6a15dc602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x44a207 in stbi__malloc ../../dependency/stb/stb_image.h:900
    #2 0x44a207 in stbi__bmp_load ../../dependency/stb/stb_image.h:4846

SUMMARY: AddressSanitizer: heap-buffer-overflow ../../src/cmft/image.cpp:1482 cmft::rgba8ToRgba32f(float*, unsigned char const*)
Shadow bytes around the buggy address:
  0x0c047fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9dd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff9df0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa[01]fa
  0x0c047fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e40: 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
==22401==ABORTING

Thanks, Manh Dung

strongcourage avatar May 29 '19 06:05 strongcourage