Skip to content

locationd: guard parabolic_peak_interp against empty/out-of-range input#38250

Open
CharlesCNorton wants to merge 1 commit into
commaai:masterfrom
CharlesCNorton:guard-parabolic-peak-interp
Open

locationd: guard parabolic_peak_interp against empty/out-of-range input#38250
CharlesCNorton wants to merge 1 commit into
commaai:masterfrom
CharlesCNorton:guard-parabolic-peak-interp

Conversation

@CharlesCNorton

Copy link
Copy Markdown

Summary

parabolic_peak_interp reads R[max_index - 1], R[max_index], and R[max_index + 1]
after a guard that only matches the exact endpoints (max_index == 0 or
max_index == len(R) - 1). An empty R, or a max_index outside [0, len(R) - 1],
therefore raises IndexError instead of being handled.

Change

Widen the guard to max_index <= 0 or max_index >= len(R) - 1 so a degenerate index
returns max_index unchanged, the same behavior the function already uses at the
boundaries where there is no neighbor to interpolate against. Valid interior peaks are
unaffected.

Test

Adds test/test_helpers.py covering a symmetric peak, the endpoints, and the previously
crashing degenerate inputs (empty array and out-of-range index).

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.
@github-actions

Copy link
Copy Markdown
Contributor

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant