Skip to content

Handle zero dimensions in ImagingOffset - #9847

Merged
hugovk merged 1 commit into
python-pillow:mainfrom
Mengxi-Xu:main
Aug 4, 2026
Merged

Handle zero dimensions in ImagingOffset#9847
hugovk merged 1 commit into
python-pillow:mainfrom
Mengxi-Xu:main

Conversation

@Mengxi-Xu

@Mengxi-Xu Mengxi-Xu commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

  • Fixed division-by-zero crash in ImagingOffset when image width or height is zero
  • Added dimension checks before performing xoffset %= im->xsize and yoffset %= im->ysize

Reference:
This PR addresses the division-by-zero issue previously reported in security advisory GHSA-f87v-9578-p47w. The fix follows the recommended approach: checking image dimensions before modulo operations and returning an empty image copy early when either dimension is zero.

@hugovk

hugovk commented Aug 4, 2026

Copy link
Copy Markdown
Member
  • Added unit tests for ImageChops.offset() with empty images, e.g., (0, 1) and (1, 0)

This is missing from the PR.

@Mengxi-Xu

Copy link
Copy Markdown
Contributor Author
  • Added unit tests for ImageChops.offset() with empty images, e.g., (0, 1) and (1, 0)

This is missing from the PR.

Yes, thank you for the reminder. I have rewritten the commit description.

@radarhere radarhere changed the title Handle zero dimensions in Offset.c Handle zero dimensions in ImagingOffset Aug 4, 2026
@hugovk
hugovk merged commit 809e559 into python-pillow:main Aug 4, 2026
63 of 65 checks passed
@hugovk

hugovk commented Aug 4, 2026

Copy link
Copy Markdown
Member

Thank you! 🎉

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.

3 participants