fix: check bounds when adding to stack in hysteresis#746
Open
Dantsz wants to merge 5 commits intoimage-rs:mainfrom
Open
fix: check bounds when adding to stack in hysteresis#746Dantsz wants to merge 5 commits intoimage-rs:mainfrom
hysteresis#746Dantsz wants to merge 5 commits intoimage-rs:mainfrom
Conversation
cospectrum
requested changes
Dec 20, 2025
non_maximum_suppression and hysteresis.
altendky
added a commit
to altendky/mujou
that referenced
this pull request
Feb 12, 2026
imageproc 0.26.0's hysteresis BFS panics when edges reach the image border: `nx - 1` on a u32 of 0 wraps to u32::MAX, causing get_pixel to panic (RuntimeError: unreachable in WASM). The BFS also only checks 6 of 8 neighbors, omitting north and northeast. Vendor the canny/non_maximum_suppression/hysteresis functions with two targeted fixes: - Bounds-check neighbor coordinates before get_pixel access - Add the two missing neighbor directions Upstream: image-rs/imageproc#705 Upstream fix PR: image-rs/imageproc#746 Removal tracked by: #69
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.
Fix for #705
The issue is that when a boundary pixel is popped from the stack, there are no checks so the unsigned subtraction can underflow like in the issue or go out of bounds in
get_pixel.I also the
(nx, ny - 1),(nx + 1, ny - 1)are not checked, I assumed that's a mistake so I added them and updated the image to match.I also ran the benchmark: