Skip to content

Reject NaN and out-of-range blur radii - #9902

Open
lazerg wants to merge 2 commits into
python-pillow:mainfrom
lazerg:fix/issue-9900-boxblur-nan
Open

Reject NaN and out-of-range blur radii#9902
lazerg wants to merge 2 commits into
python-pillow:mainfrom
lazerg:fix/issue-9900-boxblur-nan

Conversation

@lazerg

@lazerg lazerg commented Aug 25, 2026

Copy link
Copy Markdown

Fixes #9900. Alternative to #9906

Changes proposed in this pull request:

  • ImagingBoxBlur() only rejected negative radii, so NaN slipped through and (int)floatRadius was undefined behaviour, giving a garbage radius and the out of bounds write in ImagingLineBoxBlur32(). Infinity and any radius of 2**31 or more crash the same way, since they are not representable as an int either.
  • The radius is now rejected unless it is at least 0 and small enough to convert to an int, which covers GaussianBlur too.

Comment thread src/libImaging/BoxBlur.c
}
if (xradius < 0 || yradius < 0) {
/* Negated comparisons, so that NaN is rejected as well. */
if (!(xradius >= 0) || !(yradius >= 0)) {

@akx akx Aug 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To a casual reader, this looks like a very odd way to write the thing. If the idea is that this catches NaNs by... off the top of my head, some quirk of how IEEE floats work, a comment would be nice.

EDIT: a comment got added just as I was writing this. Nice!

Even nicer, though, I think, some sort of reusable float-validation function since I'm quite sure there are many other instances of this same class of bug in Pillow.

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

2 participants