Skip to content

Return BadImage for a truncated image - #3502

Merged
adamtheturtle merged 1 commit into
mainfrom
fix/3498-image-integrity-oserror
Aug 27, 2026
Merged

Return BadImage for a truncated image#3502
adamtheturtle merged 1 commit into
mainfrom
fix/3498-image-integrity-oserror

Conversation

@adamtheturtle

Copy link
Copy Markdown
Member

Fixes #3498.

Image.verify raises OSError as well as SyntaxError — for example on a
PNG whose IDAT data is present but whose IEND chunk is missing.
Image.open succeeds for such a file, so validate_image_is_image does not
reject it first, and the bare OSError escaped the request: the mock failed
to respond at all.

validate_image_integrity now catches both. open_image runs outside the
try, so anything which cannot be opened at all is still rejected by
validate_image_is_image.

Verification

make_truncated_png_file builds the file from the reproduction in the issue.
New TestImage::test_truncated tests for add_target and update_target
fail with OSError: truncated PNG file without the fix and pass with it, on
the in-memory mock, the in-memory Docker application and real Vuforia — real
Vuforia answers 422 BadImage, so the mock now matches.

The Query API needs no change: it never calls verify, and real Vuforia
accepts the same truncated PNG there, returning an empty match list. Checked
against a live account.

The new update_target test needed a ci_pattern entry; the add_target
one is already covered by the TestImage pattern.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H7tNiBpHomY5ShxZjQyWsf

``Image.verify`` raises ``OSError`` as well as ``SyntaxError`` -- for
example on a PNG whose ``IDAT`` data is present but whose ``IEND`` chunk
is missing.  ``Image.open`` succeeds for such a file, so
``validate_image_is_image`` does not reject it first and the bare
``OSError`` escaped the request.

Real Vuforia answers ``422 BadImage`` for these images, verified against
a live account, so the mock now does too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H7tNiBpHomY5ShxZjQyWsf
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.

validate_image_integrity leaks OSError instead of returning BadImage

1 participant