Floating point exception when calling `sf_current_byterate` on an opened file
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
Start with sds.c:761 and the sds_byterate call path; the report identifies division by psf->sf.frames as the failure and supplies a minimal reproducer using sf_current_byterate. Check how sf_open can leave the frame count invalid for the provided input file, then verify the reproducer no longer raises a floating point exception and valid files still report a byte rate.
Written by the indexing model from the issue text.
Description
Hello, a floating point exception occurs in the below program when provided with a specially-constructed file. This exception occurs in the sds_byterate function at location sds.c:761. The offending line of code is below:
return (psf->datalength * psf->sf.samplerate) / psf->sf.frames ;
Although the sf_open function successfully returns a file, it seems that the sf.frames property is invalid. Moving forward, potentially adding a check to the frame count for the file before performing the division would avoid this, or perhaps this is indicative of corruption that occurred in the earlier sf_open function. Thank you!
Minimal Reproducer
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "sndfile.h"
int main(int argc, char *argv[])
{
SF_INFO sfinfo;
SNDFILE *sndfile = sf_open(argv[1], SFM_READ, &sfinfo);
if(!sndfile){
return 0;
}
sf_current_byterate(sndfile);
}
Input File
https://github.com/FuturesLab/Library_Bugs/blob/main/libsndfile/1
Commit
68f6c16fe1407eff4cdde158566694c3ed666c2f
ASAN Trace
==316915==ERROR: AddressSanitizer: FPE on unknown address 0x5634745d5dbb (pc 0x5634745d5dbb bp 0x7ffcdb644420 sp 0x7ffcdb644370 T0)
#0 0x5634745d5dbb in sds_byterate /local_src/libsndfile/build_artifacts/code/src/sds.c:761:49
#1 0x5634745a7a2a in main /bugs/libsndfile/./harness/1/harness.cpp:12:5
#2 0x7f3582c29d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#3 0x7f3582c29e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#4 0x5634744bf474 in _start (/bugs/libsndfile/harness/1/harness+0x51474) (BuildId: 02cabdd8ac7f45f74e40a4f6fe7529f4eeba9554)
==316915==Register values:
rax = 0x000000000000bb80 rbx = 0x00007ffcdb644380 rcx = 0x0000000000003e80 rdx = 0x0000000000000000
rdi = 0x00007d8581fe1ea8 rsi = 0x00007d8581fe1ea8 rbp = 0x00007ffcdb644420 rsp = 0x00007ffcdb644370
r8 = 0x00000f66b017e004 r9 = 0x0000000000000000 r10 = 0x00000f66b017e007 r11 = 0x0000000000000000
r12 = 0x00007ffcdb644538 r13 = 0x00005634745a7900 r14 = 0x00005634746ccc30 r15 = 0x00007f3583136040
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: FPE /local_src/libsndfile/build_artifacts/code/src/sds.c:761:49 in sds_byterate
==316915==ABORTING
- Dominant language
- C
- Stars
- 1.7k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from libsndfile/libsndfile
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
libsndfile/libsndfile#1239 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
libsndfile/libsndfile#1238 · 2 comments ·
-
NULL pointer dereference in alac_pakt_read_decode() via unchecked alac_pakt_alloc() returnPossibly taken @Perennos claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
libsndfile/libsndfile#1220 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
libsndfile/libsndfile#1182 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
libsndfile/libsndfile#1165 ·
All issues in libsndfile/libsndfile
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
CommonLoon102/restunts-bb11#101 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100