Skip to content

fix: check bounds when adding to stack in hysteresis#746

Open
Dantsz wants to merge 5 commits intoimage-rs:mainfrom
Dantsz:hysteresis_bounds_check
Open

fix: check bounds when adding to stack in hysteresis#746
Dantsz wants to merge 5 commits intoimage-rs:mainfrom
Dantsz:hysteresis_bounds_check

Conversation

@Dantsz
Copy link
Contributor

@Dantsz Dantsz commented Dec 1, 2025

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:

Before:
1,893,753.20 ns/iter (+/- 114,337.84)
After:
1,898,263.80 ns/iter (+/- 58,917.65)

Copy link
Contributor

@cospectrum cospectrum left a comment

Choose a reason for hiding this comment

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

Could you please add tests or proptests for hysteresis function in src/edges.rs?

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
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.

2 participants

Comments