Repository navigation
Conversation
NaN fails every ordered comparison, so a NaN ratio passed validation and reached the sinc converters, where it caused an out-of-bounds read. Add nan_ratio_test covering src_simple, src_process and src_set_ratio for all converters. Fixes libsndfile#237.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #237
Problem
is_bad_src_ratio()checkedratio < min || ratio > max. Because both comparisons evaluate to false for NaN, a NaN ratio passed validation insrc_simple,src_process, andsrc_set_ratio. In the sinc converters, NaN reaches the input-index arithmetic,lrint(NaN)produces a garbage index, andcalc_output_singlereads before the filter buffer. The linear and ZOH converters also accepted NaN.Fix
Rewrite the check in
src/common.has!(ratio >= min && ratio <= max), which evaluates to true for NaN. With this one-line change, every caller ofis_bad_src_ratioreturnsSRC_ERR_BAD_SRC_RATIOon NaN. The extra negative-index guard incalc_output_singleproposed in the issue is omitted because NaN can no longer reach that path.Testing
Added
tests/nan_ratio_test.c(registered intests/CMakeLists.txt) to verify for every converter thatsrc_is_valid_ratio(NAN)is false and thatsrc_simple,src_process, andsrc_set_ratioreject a NaN ratio.Built in Release mode with
-fsanitize=address,undefinedand-DNDEBUG, then ranctest:nan_ratio_testfails). A small program callingsrc_simplewithNANandSRC_SINC_FASTESTcrashes incalc_output_single(src/src_sinc.c:420) under ASan.SRC_ERR_BAD_SRC_RATIO) with no ASan report.AI-assisted: drafted with an AI coding assistant; reproduced and tested locally before submitting.