sahaRatul / sela

SimplE Lossless Audio
https://seladoc.netlify.com/
MIT License
209 stars 23 forks source link

Program received signal SIGFPE, Arithmetic exception. #16

Closed fouzhe closed 4 years ago

fouzhe commented 6 years ago

The program will get divide-by-zero error when input this Monoaural wav file.The variable "seconds" in sela/core/encode.c:333:58 become zero.

Here is the output and ASAN information:

SimplE Lossless Audio Encoder
Copyright (c) 2015-2016. Ratul Saha
Released under MIT license

Input : ./IN/1964.wav
Output : ./IN_1/1948.sela
WAV file detected

Stream Information
------------------
Sampling Rate : 48000 Hz
Bits per sample : 16
Channels : 1 (Monoaural)

Metadata
--------
No metadata found.
[                         ]

Statistics
----------
1 frames written (0min 0sec)
==19231==AddressSanitizer: WARNING: unexpected format specifier in printf interceptor: %
 (reported once per process)
Compression Ratio : 75.00%
AddressSanitizer:DEADLYSIGNAL
=================================================================
==19231==ERROR: AddressSanitizer: FPE on unknown address 0x00000051a06d (pc 0x00000051a06d bp 0x7fff9705b4c0 sp 0x7fff97039160 T0)
    #0 0x51a06c in main /home/fouzhe/my_fuzz/sela/core/encode.c:333:58
    #1 0x7effd35d082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #2 0x41a148 in _start (/home/fouzhe/my_fuzz/sela/selaenc+0x41a148)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: FPE /home/fouzhe/my_fuzz/sela/core/encode.c:333:58 in main
==19231==ABORTING

Here is gdb information, the variable "seconds" becomes 0 when inputting this file.

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from selaenc...done.
(gdb) b 333
Breakpoint 1 at 0x51a040: file core/encode.c, line 333.
(gdb) run 1964.wav test.sela
Starting program: /home/fouzhe/my_fuzz/sela/selaenc 1964.wav test.sela
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
SimplE Lossless Audio Encoder
Copyright (c) 2015-2016. Ratul Saha
Released under MIT license

Input : 1964.wav
Output : test.sela
WAV file detected

Stream Information
------------------
Sampling Rate : 48000 Hz
Bits per sample : 16
Channels : 1 (Monoaural)

Metadata
--------
No metadata found.
[                         ]

Statistics
----------
1 frames written (0min 0sec)
==23154==AddressSanitizer: WARNING: unexpected format specifier in printf interceptor: %
 (reported once per process)
Compression Ratio : 75.00%

Breakpoint 1, main (argc=-18431, argv=<optimized out>) at core/encode.c:333
333     fprintf(stderr,"Bitrate : %d kbps\n",(out_file_size * 8)/(seconds * 1000));
(gdb) p seconds
$1 = 0
(gdb) n

Program received signal SIGFPE, Arithmetic exception.
0x000000000051a06d in main (argc=-18431, argv=<optimized out>) at core/encode.c:333
333     fprintf(stderr,"Bitrate : %d kbps\n",(out_file_size * 8)/(seconds * 1000));
(gdb) n
__asan::AsanOnDeadlySignal (signo=8, siginfo=0x7ffff7fe8bf0, context=0x7ffff7fe8ac0) at /home/fouzhe/llvm/llvm/projects/compiler-rt/lib/asan/asan_posix.cc:35
35  void AsanOnDeadlySignal(int signo, void *siginfo, void *context) {
(gdb) n
36    StartReportDeadlySignal();
(gdb) n
AddressSanitizer:DEADLYSIGNAL
37    SignalContext sig(siginfo, context);
(gdb) n
38    ReportDeadlySignal(sig);
(gdb) n
sahaRatul commented 4 years ago

Code has been rewritten, should be fixed now