-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: interpolate: do not segfault on bad boundary conditions #20732
Conversation
l, r = [(1, 0)], [(6, 0)] # 6th derivative = 0 at x[-1] for k=3 | ||
with assert_raises(ValueError): | ||
# cannot fix 6th derivative at x[-1]: does not segfault | ||
make_interp_spline(x, y, bc_type=(l, r)) | ||
|
||
l, r = [(1, 0)], [(-6, 0)] # derivative order < 0 at x[-1] | ||
with assert_raises(ValueError): | ||
# does not segfault | ||
make_interp_spline(x, y, bc_type=(l, r)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I should have put this with my original comment but could we not make one of the bad BCs on the left so we get coverage of both branches? Also if there is an edit to be made can we add match=.....
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, the left-hand side boundary condition it is. re match=...
feel free to add if you think it's essential. I'm on record that they are not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ev-br
Reference issue
What does this implement/fix?
Avoid a segfault when
make_interp_spline
receives too high derivative order for a boundary condition.The underlying issue is that the input falls through all the way down to a C routine, https://github.com/scipy/scipy/blob/main/scipy/interpolate/src/__fitpack.h#L48
and triggers a UB. (in that line,
k=3
is the spline order, andm
is the user input)Additional information
CubicSpline explicitly checks that the boundary conditions only feature 1st or 2nd derivatives.
Checks added in this PR are likely on a loose side: orders 0 and k currently raise a ValueError for a different reason; fixing these would a nice enhancement; this PR is a pure bug fix.
found while looking at https://stackoverflow.com/questions/78482220/fixing-boundary-values-on-a-spline;