Skip to content

Fix the response to a geometry that has no pixels - #113

Merged
beetlebugorg merged 1 commit into
mainfrom
fix/degenerate-geometry
Aug 30, 2026
Merged

beetlebugorg merged 1 commit into
mainfrom
fix/degenerate-geometry

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

What

The module returns 400 status code for a crop region that lies off the image, and for a crop where MagickCropImage fails. A crop side of zero is filled from the image before the cut. A resize and a watermark overlay hold a minimum of one pixel a side.

Why

Five geometries with no pixels ended the request with a 500 status or an image of one pixel.

Request Before After
crop/256x256+768+768 on 512x512 200 with an image of one pixel 400
crop/50x50+512+0 on 512x512 500 400
crop/1247x591+149+108/legacy_thumbnail/x1070/crop/895x648 on 200x136 500 400
resize/1x1!/resize/46% 500 200
watermark/0.2,0.8,ne on a 1x1 source 500 200

Row two covers one offset. An offset of 511 returned 200. An offset of 513 returned 200. Only an offset equal to the width returned 500.

go-dims returns an error for a crop whose clamped width or height reaches zero. See internal/commands/crop.go.

Verify

make -C test test
make -C test sanitize

278 cases pass. The added cases are TestCropOffsetOnTheEdge, TestCropWithoutHeight, TestResizeBelowOnePixel, and TestWatermarkOnAOnePixelSource.

TestCropXOffsetOutsideImage and TestCropYOffsetOutsideImage now assert a status. Their four golden files are deleted. No golden file moved.

The status assertions run against the server on port 8001, in test/http/test_no_error_image.c. The server on port 8000 has an error image, so a failure there returns 200 with a picture.

A crop offset at the image edge ended the request with 500. An offset
past the edge produced an image of one pixel. go-dims responds with 400
status code for both.

- Respond with 400 status code for a crop region that lies off the
  image.
- Respond with 400 status code when MagickCropImage fails. The status
  was 500.
- Fill a crop side of zero from the image before the cut.
- Clamp a resize and a watermark overlay to one pixel a side.
@beetlebugorg
beetlebugorg merged commit d828623 into main Aug 30, 2026
6 checks passed
@beetlebugorg
beetlebugorg deleted the fix/degenerate-geometry branch August 30, 2026 19:42
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.

1 participant