Fix filter3x3 panic on zero-dimension images#3055
Closed
chatman-media wants to merge 1 commit into
Closed
Conversation
filter3x3 iterated 1..width-1 / 1..height-1, which underflows when an image has a zero width or height, panicking with a subtract overflow (or wrapping to a huge range in release). Use saturating_sub so a dimension of 0 yields an empty range, matching the existing behavior for images with a dimension of 1 (no interior pixels, output left untouched). Closes image-rs#3026
Member
|
The good thing is this allows comparison with the alternative approach in #2874 . However, the other looks like a much more principled choice, rather than merely avoiding the fault it provides a fix to the input cases that improves the specification of the function. |
Author
|
Closing in favor of #2874 — that takes the more principled route by fixing the abyss policy rather than just guarding the panic. Thanks for the comparison! |
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.
Closes #3026.
imageops::filter3x3loops over1..width - 1/1..height - 1. When an image has a zero width or height, these subtractions underflow, panicking with "attempt to subtract with overflow" (debug) or wrapping to a near-u32::MAXrange (release).Switched both bounds to
saturating_sub(1)so a zero dimension yields an empty range, matching the existing behavior for a dimension of 1 (no interior pixels, output left as-is). Added a regression test covering the 0 and 1 dimension cases.Note: #3028 (the
unsharpen/gaussian-blur path) is handled separately by #3007; this only touches the independentfilter3x3code path.