Skip to content
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

Memory leaks detected #5

Closed
xiaoxiongwang opened this issue Nov 22, 2019 · 3 comments
Closed

Memory leaks detected #5

xiaoxiongwang opened this issue Nov 22, 2019 · 3 comments
Labels
bug help wanted Cannot fix it myself, need volunteer work!

Comments

@xiaoxiongwang
Copy link
Contributor

xiaoxiongwang commented Nov 22, 2019

Tested in Ubuntu 16.04, 64bit

I use the following command with the file:

./wavegain wavegain_memory_gain.wav

and get:

Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
*** buffer overflow detected ***: ./wavegain terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f090b3a57e5]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f090b44715c]
/lib/x86_64-linux-gnu/libc.so.6(+0x117160)[0x7f090b445160]
/lib/x86_64-linux-gnu/libc.so.6(__fread_chk+0x165)[0x7f090b445855]
./wavegain[0x40f797]
./wavegain[0x410ee0]
./wavegain[0x41e20d]
./wavegain[0x41c660]
./wavegain[0x40374e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f090b34e830]
./wavegain[0x403ca9]
======= Memory map: ========
00400000-0042a000 r-xp 00000000 103:01 20397804                          wavegain/wavegain
00629000-0062a000 r--p 00029000 103:01 20397804                          wavegain/wavegain
0062a000-0062b000 rw-p 0002a000 103:01 20397804                          wavegain/wavegain
0062b000-00668000 rw-p 00000000 00:00 0 
00a1c000-00a3d000 rw-p 00000000 00:00 0                                  [heap]
7f090b118000-7f090b12e000 r-xp 00000000 103:01 10490464                  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f090b12e000-7f090b32d000 ---p 00016000 103:01 10490464                  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f090b32d000-7f090b32e000 rw-p 00015000 103:01 10490464                  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f090b32e000-7f090b4ee000 r-xp 00000000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b4ee000-7f090b6ee000 ---p 001c0000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b6ee000-7f090b6f2000 r--p 001c0000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b6f2000-7f090b6f4000 rw-p 001c4000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b6f4000-7f090b6f8000 rw-p 00000000 00:00 0 
7f090b6f8000-7f090b800000 r-xp 00000000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090b800000-7f090b9ff000 ---p 00108000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090b9ff000-7f090ba00000 r--p 00107000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090ba00000-7f090ba01000 rw-p 00108000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090ba01000-7f090ba27000 r-xp 00000000 103:01 10485855                  /lib/x86_64-linux-gnu/ld-2.23.so
7f090bbf5000-7f090bbf9000 rw-p 00000000 00:00 0 
7f090bc25000-7f090bc26000 rw-p 00000000 00:00 0 
7f090bc26000-7f090bc27000 r--p 00025000 103:01 10485855                  /lib/x86_64-linux-gnu/ld-2.23.so
7f090bc27000-7f090bc28000 rw-p 00026000 103:01 10485855                  /lib/x86_64-linux-gnu/ld-2.23.so
7f090bc28000-7f090bc29000 rw-p 00000000 00:00 0 
7ffde0294000-7ffde02b6000 rw-p 00000000 00:00 0                          [stack]
7ffde0339000-7ffde033c000 r--p 00000000 00:00 0                          [vvar]
7ffde033c000-7ffde033e000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted

I use AddressSanitizer to build wavegain, this file can memory leak with the following command:

./wavegain wavegain_memory_gain.wav

This is the ASAN information:

Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
Warning: Unexpected EOF in reading WAV header
 Unrecognized file format for wavegain_memory_gain.wav

 WaveGain Processing completed normally

=================================================================
==3874==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 92 byte(s) in 1 object(s) allocated from:
    #0 0x7f6ca685030f in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x6230f)
    #1 0x4111bc in alloc_node wavegain/main.c:70
    #2 0x4113d3 in add_to_list wavegain/main.c:104
    #3 0x403d7e in process_argument wavegain/recurse.c:583
    #4 0x4144f1 in main wavegain/main.c:718
    #5 0x7f6ca613b82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f6ca6886602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x4097e8 in wav_open wavegain/audio.c:646
    #2 0x407832 in open_audio_file wavegain/audio.c:362
    #3 0x414dec in get_gain wavegain/wavegain.c:181
    #4 0x41198c in process_files wavegain/main.c:197
    #5 0x41453e in main wavegain/main.c:729
    #6 0x7f6ca613b82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 132 byte(s) leaked in 2 allocation(s).
@MestreLion MestreLion added bug help wanted Cannot fix it myself, need volunteer work! labels Jul 4, 2020
MestreLion added a commit that referenced this issue Jul 5, 2020
This might shed some light on current open issues, namely #2, #5 and #6.
@MestreLion
Copy link
Owner

I wasn't able to reproduce the Buffer Overflow using your test file and the binary compiled with v1.3.1-1, wavegain worked just fine, detecting the file as invalid and exiting normally:

$ git checkout 1.3.1-1
$ make debug  # output ommited. Same result using `make`  (== `make release`)
$ ./wavegain test/memory_leak.wav
Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
Warning: Unexpected EOF in reading WAV header
 Unrecognized file format for test/memory_leak.wav.


 WaveGain Processing completed normally

But I did reproduce the Memory Leak when compiling with Address Sanitizer like you did, and had a very similar output, tho "only" 61 bytes leaked, not 132:

$ git checkout 1.3.1-1
$ CFLAGS='-fsanitize=address -static-libasan' make debug
$ ./wavegain test/memory_leak.wav
Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
Warning: Unexpected EOF in reading WAV header
 Unrecognized file format for test/memory_leak.wav.


 WaveGain Processing completed normally

=================================================================
==22785==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x5561899b05a0 in malloc (/home/rodrigo/work/wavegain/wavegain-1.3.1/wavegain+0xca5a0)
    #1 0x5561899f91dc in wav_open /home/rodrigo/work/wavegain/wavegain-1.3.1/audio.c:646
    #2 0x5561899f6b9f in open_audio_file /home/rodrigo/work/wavegain/wavegain-1.3.1/audio.c:362
    #3 0x556189a05f19 in get_gain /home/rodrigo/work/wavegain/wavegain-1.3.1/wavegain.c:181
    #4 0x556189a01a83 in process_files /home/rodrigo/work/wavegain/wavegain-1.3.1/main.c:197
    #5 0x556189a0558f in main /home/rodrigo/work/wavegain/wavegain-1.3.1/main.c:729
    #6 0x7efddaa33b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Direct leak of 21 byte(s) in 1 object(s) allocated from:
    #0 0x556189948fb8 in strdup (/home/rodrigo/work/wavegain/wavegain-1.3.1/wavegain+0x62fb8)
    #1 0x556189a01264 in alloc_node /home/rodrigo/work/wavegain/wavegain-1.3.1/main.c:70
    #2 0x556189a0147f in add_to_list /home/rodrigo/work/wavegain/wavegain-1.3.1/main.c:104
    #3 0x5561899f2e7a in process_argument /home/rodrigo/work/wavegain/wavegain-1.3.1/recurse.c:583
    #4 0x556189a054f0 in main /home/rodrigo/work/wavegain/wavegain-1.3.1/main.c:718
    #5 0x7efddaa33b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: 61 byte(s) leaked in 2 allocation(s).

@MestreLion
Copy link
Owner

It seems the leak is fixed when using a 32-bit executable:

$ git checkout 1.3.1-1
$ CFLAGS='-fsanitize=address -static-libasan -m32' make debug
$ ./wavegain test/memory_leak.wav
Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
Warning: Unexpected EOF in reading WAV header
 Unrecognized file format for test/memory_leak.wav.


 WaveGain Processing completed normally

@MestreLion
Copy link
Owner

Fixed in 8f14080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted Cannot fix it myself, need volunteer work!
Projects
None yet
Development

No branches or pull requests

2 participants