Skip to content

Reject non-finite radius in BoxBlur - #9906

Open
JonnasFigueiredo wants to merge 1 commit into
python-pillow:mainfrom
JonnasFigueiredo:fix/boxblur-non-finite-radius
Open

Reject non-finite radius in BoxBlur#9906
JonnasFigueiredo wants to merge 1 commit into
python-pillow:mainfrom
JonnasFigueiredo:fix/boxblur-non-finite-radius

Conversation

@JonnasFigueiredo

@JonnasFigueiredo JonnasFigueiredo commented Aug 25, 2026

Copy link
Copy Markdown

Fixes #9900. Alternative to #9902

BoxBlur validates radius >= 0 in Python, but nan < 0 (and inf < 0) is False, so a non-finite radius slipped through the check and reached the C box_blur, causing a heap-buffer-overflow (found by fuzzing).

This extends the existing radius validation to reject non-finite values, raising ValueError just like a negative radius does:

>>> from PIL import ImageFilter
>>> ImageFilter.BoxBlur(float("nan"))
ValueError: radius must be a finite number >= 0

Added tests for nan/inf, both as a scalar and per-axis. I verified against the compiled extension that valid radii still work and that nan/inf/negative radii are rejected.

BoxBlur only checked `radius < 0`, so a NaN or infinite radius passed the
Python-level validation (`nan < 0` is False) and reached the C `box_blur`,
causing a heap-buffer-overflow. Validate that the radius is a finite,
non-negative number and raise ValueError, as is already done for negative
radii.
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.

ImageFilter.BoxBlur(float("nan")) causes a heap-buffer-overflow

1 participant