Skip to content
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

Merged
merged 5 commits into from
May 18, 2024

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented May 17, 2024

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, and m is the user input)

Additional information

@ev-br ev-br added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.interpolate labels May 17, 2024
Comment on lines 1352 to 1360
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))
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

@j-bowhay j-bowhay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ev-br

@j-bowhay j-bowhay merged commit 10c6747 into scipy:main May 18, 2024
@j-bowhay j-bowhay added this to the 1.14.0 milestone May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants