Refuse a size whose computed side exceeds the maximum (closes #241) #258

Merged
clawbot merged 2 commits from issue-241-bound-computed-side into next 2026-10-13 09:44:45 +02:00
Collaborator

Closes #241.

A side given as 0 is computed from the source's proportions, and nothing held it to the 8192 a requested side is held to, so 0x8192 of a 3000x600 source was resized to 40960x8192 and encoded. As decided on the issue, such a size is refused, not clamped.

  • targetDimensions now returns ErrOutputTooLarge for a side above MaxOutputDimension. Process calls it right after the existing check of the source's dimensions and returns before the resize and the encode; the existing defer gives the processing slot back.
  • Both image routes answer it 400 with the JSON error body: size too large for the source: the side computed from its proportions is above 8192.
  • The refusal is a processing error, and only a failed upstream fetch reaches the negative cache. The new route test requests the same sources at smaller sizes after the refusals.
  • imgcache.MaxDimension is now defined as imageprocessor.MaxOutputDimension (imgcache already imports imageprocessor; the reverse would be a cycle), so the request limit and the output limit are one value.

Judgement call: the route test is in internal/server, which already builds both routes against a test upstream, rather than a second handler setup in internal/handlers.

Not covered: fit=outside with both sides given can still make a side above 8192, filed as #257.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/pixa/issues/241. A side given as `0` is computed from the source's proportions, and nothing held it to the 8192 a requested side is held to, so `0x8192` of a 3000x600 source was resized to 40960x8192 and encoded. As decided on the issue, such a size is refused, not clamped. - `targetDimensions` now returns `ErrOutputTooLarge` for a side above `MaxOutputDimension`. `Process` calls it right after the existing check of the source's dimensions and returns before the resize and the encode; the existing `defer` gives the processing slot back. - Both image routes answer it 400 with the JSON error body: `size too large for the source: the side computed from its proportions is above 8192`. - The refusal is a processing error, and only a failed upstream fetch reaches the negative cache. The new route test requests the same sources at smaller sizes after the refusals. - `imgcache.MaxDimension` is now defined as `imageprocessor.MaxOutputDimension` (imgcache already imports imageprocessor; the reverse would be a cycle), so the request limit and the output limit are one value. Judgement call: the route test is in `internal/server`, which already builds both routes against a test upstream, rather than a second handler setup in `internal/handlers`. Not covered: `fit=outside` with both sides given can still make a side above 8192, filed as https://git.eeqj.de/sneak/pixa/issues/257. Model: opus-5-5
clawbot added the needs-review label 2026-10-13 09:22:22 +02:00
clawbot self-assigned this 2026-10-13 09:22:22 +02:00
clawbot added 2 commits 2026-10-13 09:22:23 +02:00
Failing tests first. Through both image routes, 0x8192 of a 3000x600
source and 8192x0 of a 600x3000 source must answer 400 with the JSON
error body; orig, a size with both sides given and a 0 side whose
computed side stays within 8192 must be served as before, after the
refusals. In the image processor, a 0 side computed to exactly 8192 is
kept and one above is refused with ErrOutputTooLarge, which does not
exist yet.

Model: opus-5-5
A side given as 0 is computed from the source's proportions, and
nothing held it to 8192: 0x8192 of a 3000x600 source was resized to
40960x8192 and encoded. Process now refuses such a size with
ErrOutputTooLarge once it knows the source's dimensions, before the
resize and the encode, and both image routes answer it 400 with the
JSON error body. It is a processing error, not a failed fetch, so it
is never negative-cached. imgcache.MaxDimension is now
imageprocessor.MaxOutputDimension, so the request limit and the output
limit are one value. README.md says it under Routes and Encrypted URLs.

Model: opus-5-5
Author
Collaborator

PASS

Model: opus-5-5

PASS Model: opus-5-5
clawbot merged commit d8760c40a1 into next 2026-10-13 09:44:45 +02:00
clawbot deleted branch issue-241-bound-computed-side 2026-10-13 09:44:45 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#258