locationd: guard parabolic_peak_interp against empty/out-of-range input#38250
Open
CharlesCNorton wants to merge 1 commit into
Open
locationd: guard parabolic_peak_interp against empty/out-of-range input#38250CharlesCNorton wants to merge 1 commit into
CharlesCNorton wants to merge 1 commit into
Conversation
parabolic_peak_interp reads R[max_index-1 .. max_index+1] after a guard that only matches the exact endpoints, so an empty R or an out-of-range max_index raised IndexError. Widen the guard to max_index <= 0 or max_index >= len(R) - 1 so a degenerate index returns max_index unchanged, the same as the existing boundary case. Adds a test.
Contributor
Process replay diff reportReplays driving segments through this PR and compares the behavior to master. ✅ 0 changed, 66 passed, 0 errors |
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.
Summary
parabolic_peak_interpreadsR[max_index - 1],R[max_index], andR[max_index + 1]after a guard that only matches the exact endpoints (
max_index == 0ormax_index == len(R) - 1). An emptyR, or amax_indexoutside[0, len(R) - 1],therefore raises
IndexErrorinstead of being handled.Change
Widen the guard to
max_index <= 0 or max_index >= len(R) - 1so a degenerate indexreturns
max_indexunchanged, the same behavior the function already uses at theboundaries where there is no neighbor to interpolate against. Valid interior peaks are
unaffected.
Test
Adds
test/test_helpers.pycovering a symmetric peak, the endpoints, and the previouslycrashing degenerate inputs (empty array and out-of-range index).