Skip to content

Avoid subtract overflow in filter3x3 on zero-dimension images#3073

Closed
SAY-5 wants to merge 1 commit into
image-rs:mainfrom
SAY-5:fix-filter3x3-zero-dimension-panic
Closed

Avoid subtract overflow in filter3x3 on zero-dimension images#3073
SAY-5 wants to merge 1 commit into
image-rs:mainfrom
SAY-5:fix-filter3x3-zero-dimension-panic

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

filter3x3 reads its dimensions and then loops 1..width - 1 / 1..height - 1. On an image with zero width or height those subtractions underflow and panic with "attempt to subtract with overflow" (reported in #3026).

Such an image has no interior pixels to filter, so this returns the empty output buffer early, matching how resize already handles the empty case. Added a regression test covering both zero-width and zero-height inputs.

Fixes #3026.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@RunDevelopment

Copy link
Copy Markdown
Member

Thanks for the PR. I think this might be a duplicate of #3055 or #2874.

@SAY-5

SAY-5 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

You're right, this overlaps #3055 and the abyss-policy fix in #2874 supersedes it. Closing in favor of #2874 since that addresses the root cause rather than just guarding the underflow. Thanks!

@SAY-5 SAY-5 closed this Jul 18, 2026
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.

Panic in filter3x3() on zero-dimension image due to unsigned integer underflow

2 participants