Add check for positive xsize/ysize in ImagingFliDecode by Yay295 · Pull Request #8406 · python-pillow/Pillow

@Yay295

Fixes #8405

I put the check near the top, but is there any valid reason xsize or ysize would be 0, and the check would need to be later in the code?

@Yay295

@radarhere

is there any valid reason xsize or ysize would be 0

No. Images that say one of their dimensions are zero will be stopped at

if not self.mode or self.size[0] <= 0 or self.size[1] <= 0:
msg = "not identified by this driver"
raise SyntaxError(msg)

Even if you consider just the C decoding process, we have

if (state->xsize <= 0 || state->xsize + state->xoff > (int)im->xsize ||
state->ysize <= 0 || state->ysize + state->yoff > (int)im->ysize) {
PyErr_SetString(PyExc_ValueError, "tile cannot extend outside image");
return NULL;

@radarhere

My minor concern with this strategy is that we could make someone reading the code think that xsize might be zero, which as I've said, shouldn't happen.

I've created #8408 as an alternative to this.

@radarhere

#8408 has been merged instead.