kamalmostafa / minimodem

general-purpose software audio FSK modem
http://www.whence.com/minimodem
Other
846 stars 113 forks source link

segfaults when receiving stereo input file #1

Closed goblin closed 10 years ago

goblin commented 10 years ago

I get segfaults when attempting to receive from flac files. Files were produced with minimodem and then played back over speakers, recorded to a mobile phone and then played back to a microphone (as a test). Unfortunately github doesn't allow me to include wave/flac files, but here's more or less what happens:

$ ./minimodem -f cut.flac -r 300
*** Error in `./minimodem': free(): invalid pointer: 0x0000000002118180 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7aa16)[0x7f35369aea16]
/lib/x86_64-linux-gnu/libc.so.6(+0x7b793)[0x7f35369af793]
/usr/lib/x86_64-linux-gnu/libFLAC.so.8(FLAC__stream_decoder_finish+0x7b)[0x7f353583541b]
/usr/lib/x86_64-linux-gnu/libsndfile.so.1(+0x11449)[0x7f3536fef449]
/usr/lib/x86_64-linux-gnu/libsndfile.so.1(+0x63f8)[0x7f3536fe43f8]
./minimodem[0x4052fa]
./minimodem[0x403939]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f3536955995]
./minimodem[0x403b7b]
======= Memory map: ========
00400000-00409000 r-xp 00000000 fe:00 68366752                           /home/goblin/soft/minimodem/I/bin/minimodem
00609000-0060a000 rw-p 00009000 fe:00 68366752                           /home/goblin/soft/minimodem/I/bin/minimodem
020d2000-02135000 rw-p 00000000 00:00 0                                  [heap]

(...)

and here's what Valgrind shows:

$ valgrind ./minimodem -f cut.flac -r 300
==21446== Memcheck, a memory error detector
==21446== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==21446== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==21446== Command: ./minimodem -f cut.flac -r 300
==21446== 
==21446== Invalid write of size 4
==21446==    at 0x5992E38: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x5993F71: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x599407C: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x598A159: sf_readf_float (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x406297: sa_sndfile_read (simpleaudio-sndfile.c:49)
==21446==    by 0x402AF7: main (minimodem.c:925)
==21446==  Address 0xa002b70 is 0 bytes after a block of size 16,000 alloc'd
==21446==    at 0x4C294A0: malloc (vg_replace_malloc.c:291)
==21446==    by 0x4028C2: main (minimodem.c:847)
==21446== 
==21446== Invalid write of size 4
==21446==    at 0x5992E38: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x59931C1: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x7197F8E: ??? (in /usr/lib/x86_64-linux-gnu/libFLAC.so.8.3.0)
==21446==    by 0x719A33F: FLAC__stream_decoder_process_single (in /usr/lib/x86_64-linux-gnu/libFLAC.so.8.3.0)
==21446==    by 0x5993F37: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x599407C: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x598A159: sf_readf_float (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x406297: sa_sndfile_read (simpleaudio-sndfile.c:49)
==21446==    by 0x402AF7: main (minimodem.c:925)
==21446==  Address 0xa002b70 is 0 bytes after a block of size 16,000 alloc'd
==21446==    at 0x4C294A0: malloc (vg_replace_malloc.c:291)
==21446==    by 0x4028C2: main (minimodem.c:847)
==21446== 
==21446== Invalid write of size 8
==21446==    at 0x4C2EDD7: memset (mc_replace_strmem.c:1055)
==21446==    by 0x59AB305: ??? (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x598A1E0: sf_readf_float (in /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.25)
==21446==    by 0x406297: sa_sndfile_read (simpleaudio-sndfile.c:49)
==21446==    by 0x402AF7: main (minimodem.c:925)
==21446==  Address 0xa002b70 is 0 bytes after a block of size 16,000 alloc'd
==21446==    at 0x4C294A0: malloc (vg_replace_malloc.c:291)
==21446==    by 0x4028C2: main (minimodem.c:847)
==21446== 
==21446== 
==21446== HEAP SUMMARY:
==21446==     in use at exit: 103,640 bytes in 986 blocks
==21446==   total heap usage: 13,871 allocs, 12,885 frees, 1,353,789 bytes allocated
==21446== 
==21446== LEAK SUMMARY:
==21446==    definitely lost: 16,000 bytes in 1 blocks
==21446==    indirectly lost: 0 bytes in 0 blocks
==21446==      possibly lost: 0 bytes in 0 blocks
==21446==    still reachable: 87,640 bytes in 985 blocks
==21446==         suppressed: 0 bytes in 0 blocks
==21446== Rerun with --leak-check=full to see details of leaked memory
==21446== 
==21446== For counts of detected and suppressed errors, rerun with: -v
==21446== ERROR SUMMARY: 9216 errors from 3 contexts (suppressed: 2 from 2)

I've compiled commit 3c227b516a0abd6daf1e1da82a12d3f20995625c from source.

kamalmostafa commented 10 years ago

Thanks for the report! Yes, I can reproduce this bug, but only with stereo flac files. In my testing, minimodem reads mono flac files (matching what it writes) just fine. Can you confirm that (a) your failure is with a stereo flac and (b) that you get proper results with a mono flac? The 'file' command will indicate whether your file is stereo or mono.

goblin commented 10 years ago

Thanks Kamal, yes, you're right, I only get this with stereo files. After throwing out one channel everything works fine :-)

In this case, perhaps a more graceful failure would be appreciated (i.e. just check if it's stereo at the beginning and if it is, print an error message and exit).

kamalmostafa commented 10 years ago

The crash is now fixed, as indicated below. Thanks again, goblin.

$ minimodem -f /tmp/stereo.flac -r 300
/tmp/stereo.flac: input stream must be 1-channel (not 2)
deckar01 commented 6 years ago

It would be nice if channels after the first were ignored and there was a warning about the ignored channels. In my use case, the audio files I am receiving have identical signals on the left and right channels.