Skip to content

Fix zero-dimension simplified writes - #925

Closed
arthuz-th wants to merge 1 commit into
pnggroup:libpng18from
arthuz-th:fix/simplified-write-zero-dimensions-current
Closed

arthuz-th wants to merge 1 commit into
pnggroup:libpng18from
arthuz-th:fix/simplified-write-zero-dimensions-current

Conversation

@arthuz-th

Copy link
Copy Markdown

Fixes #489.

The simplified write path computes 0xffffffffU / png_row_stride in png_image_write_main(). With image.width == 0, png_row_stride is zero, so UBSan reports a division-by-zero before invalid dimensions are rejected.

This implements the maintainer-proposed fix in #489: reject zero width/height in png_image_write_init() before creating the write structures.

Validation against current libpng18 base 964b4135949703b705fc760fc3fb546b86e5ab47:

  • Sanitizer build (-fsanitize=address,undefined): 0x1 and 1x0 fail cleanly; a 1x1 control succeeds; no ASan/UBSan diagnostic was observed.
  • Sanitizer-built pngtest on pngbar.png: PASS (323 zero samples) and libpng passes test.

The change is intentionally local to simplified write initialization.

AI assistance disclosure: this patch and validation were prepared with AI assistance and reviewed against the current source and observed sanitizer/test results.

@ctruta

ctruta commented Oct 12, 2026

Copy link
Copy Markdown
Member

Closing as a duplicate of PR #923.

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.

Division by zero error in png_image_write_main if Image width is zero

2 participants