New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heap-buffer-overflow in ok-file-formats/ok_wav.c:742 ok_wav_decode_ms_adpcm_data() #4

Closed
moonAgirl opened this Issue Dec 31, 2018 · 7 comments

Comments

Projects
None yet
2 participants
@moonAgirl
Copy link

moonAgirl commented Dec 31, 2018

Test Version

dev version, git clone https://github.com/brackeen/ok-file-formats.git

Test Program

#include <stdio.h>
#include "ok_wav.h"

int main(int _argc, char **_argv) {
    FILE *file = fopen(_argv[1], "rb");
    ok_wav *image = ok_wav_read(file,0);
    fclose(file);
    ok_wav_free(image);
    return 0;
}

$ gcc -o wav_decode  wav_decode.c ok_wav.h ok_wav.c

Asan Debug Information

➜  ok-file-formats git:(master) ✗ ./wav_decode-asan ./wav_out/crashes/id:000000,sig:06,src:000016,op:arith8,pos:38,val:-1 
=================================================================
==50264==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62a000005824 at pc 0x00000040b2e0 bp 0x7ffc94e053b0 sp 0x7ffc94e053a0
WRITE of size 2 at 0x62a000005824 thread T0
    #0 0x40b2df in ok_wav_decode_ms_adpcm_data /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:742
    #1 0x40b2df in ok_wav_decode_data /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:861
    #2 0x40e6ba in ok_wav_decode_wav_file /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:981
    #3 0x40f8b4 in ok_wav_decode /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:1138
    #4 0x40f8b4 in ok_wav_read /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:114
    #5 0x400ffc in main /home/moonagirl/megic_afl/ok-file-formats/wav_decode.c:6
    #6 0x7f0f2cee882f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #7 0x401108 in _start (/home/moonagirl/megic_afl/ok-file-formats/wav_decode-asan+0x401108)

0x62a000005824 is located 0 bytes to the right of 22052-byte region [0x62a000000200,0x62a000005824)
allocated by thread T0 here:
    #0 0x7f0f2d32a602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x4099b0 in ok_wav_decode_ms_adpcm_data /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:689
    #2 0x4099b0 in ok_wav_decode_data /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:861

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/moonagirl/megic_afl/ok-file-formats/ok_wav.c:742 ok_wav_decode_ms_adpcm_data
Shadow bytes around the buggy address:
  0x0c547fff8ab0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c547fff8ac0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c547fff8ad0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c547fff8ae0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c547fff8af0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c547fff8b00: 00 00 00 00[04]fa fa fa fa fa fa fa fa fa fa fa
  0x0c547fff8b10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c547fff8b20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c547fff8b30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c547fff8b40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c547fff8b50: 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
==50264==ABORTING

POC file

https://github.com/moonAgirl/Bugs/blob/master/ok-file-formats/2018-12-31-01-heap-buffer-overflow.wav

@brackeen

This comment has been minimized.

Copy link
Owner

brackeen commented Dec 31, 2018

Hi, thanks for submitting the issue.

Was this found using the same input sources as the test code? Or do you have a different set of input sources?

@moonAgirl

This comment has been minimized.

Copy link

moonAgirl commented Jan 2, 2019

i use

#include <stdio.h>
#include "ok_wav.h"

int main(int _argc, char **_argv) {
    FILE *file = fopen(_argv[1], "rb");
    ok_wav *image = ok_wav_read(file,0);
    fclose(file);
    ok_wav_free(image);
    return 0;
}

same as test code

@moonAgirl

This comment has been minimized.

Copy link

moonAgirl commented Jan 2, 2019

@brackeen

This comment has been minimized.

Copy link
Owner

brackeen commented Jan 2, 2019

Sorry, I wasn't clear in my question. It looks like you're using AFL. By "input sources" I meant to say "input test cases" - the input WAV files that AFL uses to generate its own test cases.

Since the ok-file-formats test code has its own WAV file input test cases (generated from CMakeLists.txt), if you've found another crash, either 1) the existing input test cases are incomplete or 2) I never ran AFL long enough to find a crash like this. I'm wondering if you have input test cases that are better or more complete than the existing ones, and if so, if I could take a look at them.

@moonAgirl

@moonAgirl

This comment has been minimized.

Copy link

moonAgirl commented Jan 2, 2019

@moonAgirl

This comment has been minimized.

Copy link

moonAgirl commented Jan 2, 2019

@brackeen

This comment has been minimized.

Copy link
Owner

brackeen commented Jan 2, 2019

Ah, thank you, it is appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment