Skip to content

bound dilate and erode width to avoid mask-size overflow - #4548

Merged
lovell merged 2 commits into
lovell:mainfrom
metsw24-max:dilate-erode-bound-width
Jun 17, 2026
Merged

bound dilate and erode width to avoid mask-size overflow#4548
lovell merged 2 commits into
lovell:mainfrom
metsw24-max:dilate-erode-bound-width

Conversation

@metsw24-max

Copy link
Copy Markdown
Contributor

Unbounded dilate/erode width overflows the mask size

dilate() and erode() accept any positive integer, unlike the sibling median() which bounds its window to 1 to 1000, so an oversized width reaches the native Dilate/Erode where the structuring element is sized as 2 * width + 1 and passed to new_matrix; read through AttrAsUint32 into an int, a width of 2^30 wraps that signed size negative and 2^32 narrows it to zero, silently dropping the operation. Bounded the width to match median so the value can no longer reach that calculation.

@lovell

lovell commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR to fix this. Is there a reason for the 1000 limit? I think it might need to be a bit higher than this, perhaps 65536 (1 << 16)?

@lovell lovell added this to the v0.35.2 milestone Jun 17, 2026
@metsw24-max

Copy link
Copy Markdown
Contributor Author

No strong reason for 1000, I just matched the bound median() uses for its window. 65536 is fine here. The only value that needs guarding is the 2 * width + 1 mask size, and at 65536 that comes to 131073, still well within int. Pushed a change bounding both to 1..65536.

@lovell
lovell merged commit ab52866 into lovell:main Jun 17, 2026
32 checks passed
@lovell

lovell commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants