fix(image-downloader): detect image type from magic bytes, not URL extension by pmespresso · Pull Request #1396 · anthropics/claude-code-action (original) (raw)

@pmespresso @claude

GitHub serves pasted attachments from /user-attachments/assets/ with no file extension, so getImageExtension() silently defaulted to ".png". When the bytes are actually JPEG/GIF/WebP the downloaded file is mislabeled, and the Read tool then sends a base64 image whose declared media_type doesn't match its magic bytes — which the Anthropic API rejects with 400 invalid_request_error ("image was specified using the image/png media type, but the image appears to be a image/jpeg image").

Sniff the real format from the buffer's magic bytes after download and only fall back to the URL-based extension when the signature is unrecognized. Adds a regression test for a JPEG at an extensionless URL.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com