A .jpg whose bytes are not a real JPEG — HEIC/RAW, or an error body saved as an image — makes sharp/libvips throw:
Error: Input file contains unsupported image format (sharp)
VipsForeignLoad: ".../original.jpg" is not a known file format (vips)
The image index path logged that at warn, so every such cloud file opened one error-hub ticket. 3 duplicates were collapsed into this root (BIT-31438, BIT-31619, BIT-31649).
Fix
Detect the format by magic bytes before calling vips (per the 21/10 triage):
New isDecodableImage(file) in corrupt-source.ts reads the first 12 bytes and accepts JPEG / PNG / GIF / BMP / TIFF / WebP; anything else (HEIC, RAW, JSON/HTML error bodies, empty files) is rejected.
ArchiveService.index calls it right after the file is resolved and throws CorruptSource("unsupported_image_format"). The existing catch (wired by BIT-31621) marks the file FAILED once, logs at info, and never reaches the error hub.
Defence in depth: isCorruptSourceMessage is extended to also match sharp's Input file contains unsupported image format / unsupported image format wording, so a decoder failure that slips past the magic-byte check is still classified as source damage rather than a warn.
Unreadable files return true from isDecodableImage so the existing download/stat flow surfaces the real I/O error instead.
Stacking
Stacked on #93 (BIT-31621), which introduced corrupt-source.ts and wired the image/video catch blocks. Base is fix/BIT-31621-moov-corrupt-source; once #93 merges to main this PR auto-retargets and the diff stays a single commit.
Verification
vitest run apps/api/src/archive/ → 13 passed, 2 skipped (incl. new isDecodableImage cases: JPEG/PNG/WebP accepted; HEIC, JSON error body, empty rejected).
tsc --noEmit -p apps/api → 0 errors in archive/ (remaining 43 are pre-existing in sports/service.ts).
Error-loop disposition
Fix is in this branch (not main yet); deploy via webhook after merge. Include <!-- paperclip-error-loop-fix-pending-deploy:cluster:202a64490429 --> when closing as done.
## Root cause
A `.jpg` whose bytes are not a real JPEG — HEIC/RAW, or an error body saved as an image — makes `sharp`/libvips throw:
- `Error: Input file contains unsupported image format` (sharp)
- `VipsForeignLoad: ".../original.jpg" is not a known file format` (vips)
The image `index` path logged that at `warn`, so every such cloud file opened one error-hub ticket. 3 duplicates were collapsed into this root (BIT-31438, BIT-31619, BIT-31649).
## Fix
Detect the format by **magic bytes before calling vips** (per the 21/10 triage):
- New `isDecodableImage(file)` in `corrupt-source.ts` reads the first 12 bytes and accepts JPEG / PNG / GIF / BMP / TIFF / WebP; anything else (HEIC, RAW, JSON/HTML error bodies, empty files) is rejected.
- `ArchiveService.index` calls it right after the file is resolved and throws `CorruptSource("unsupported_image_format")`. The existing catch (wired by BIT-31621) marks the file `FAILED` once, logs at `info`, and never reaches the error hub.
- Defence in depth: `isCorruptSourceMessage` is extended to also match sharp's `Input file contains unsupported image format` / `unsupported image format` wording, so a decoder failure that slips past the magic-byte check is still classified as source damage rather than a warn.
Unreadable files return `true` from `isDecodableImage` so the existing download/stat flow surfaces the real I/O error instead.
## Stacking
Stacked on **#93 (BIT-31621)**, which introduced `corrupt-source.ts` and wired the image/video catch blocks. Base is `fix/BIT-31621-moov-corrupt-source`; once #93 merges to `main` this PR auto-retargets and the diff stays a single commit.
## Verification
- `vitest run apps/api/src/archive/` → 13 passed, 2 skipped (incl. new `isDecodableImage` cases: JPEG/PNG/WebP accepted; HEIC, JSON error body, empty rejected).
- `tsc --noEmit -p apps/api` → 0 errors in `archive/` (remaining 43 are pre-existing in `sports/service.ts`).
## Error-loop disposition
Fix is in this branch (not `main` yet); deploy via webhook after merge. Include `<!-- paperclip-error-loop-fix-pending-deploy:cluster:202a64490429 -->` when closing as done.
Paperclip-Issue: BIT-31229
Paperclip-Run: 8b98a125-c9b2-4c2f-b05a-b35054c9eb5b
A .jpg whose bytes are HEIC/RAW or an error body (not a real JPEG) makes
sharp/vips throw "Input file contains unsupported image format" /
VipsForeignLoad "is not a known file format". The image index path logged
that at warn, so every such file opened one error-hub ticket (3 duplicates
collapsed into BIT-31229).
Detect the format by magic bytes before calling vips: isDecodableImage
accepts JPEG/PNG/GIF/BMP/TIFF/WebP and rejects anything else, throwing
CorruptSource("unsupported_image_format"). The existing catch (BIT-31621)
marks it FAILED once at info and never reaches the error hub. Also extend
isCorruptSourceMessage to match sharp's unsupported-format wording, so a
decoder failure that slips past the magic bytes is still classified as
source damage.
Stacked on BIT-31621 (which introduced corrupt-source.ts and wired the
image/video catch blocks).
Paperclip-Issue: BIT-31229
Paperclip-Run: 8b98a125-c9b2-4c2f-b05a-b35054c9eb5b
Detail: failed contexts: ci / rust (pull_request), ci / typescript (pull_request)
The bot did not approve or schedule a merge for this head.
Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run.
@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#94: CI is red on the PR head.
- Head: `159a0909edf2`
- Detail: failed contexts: ci / rust (pull_request), ci / typescript (pull_request)
- The bot did **not** approve or schedule a merge for this head.
- Fix the branch, approve as CTO, or close the PR. The bot re-checks on the next run.
<!-- gitea-autopilot-escalation kind=ci_failure sha=159a0909edf2 -->
This branch sits on #93. Merging the #93 branch after it took main brings in
#90, #91, #95 and the rest of main with no conflicts; the magic-byte check
before vips and the unsupported image format message stay as they were.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Root cause
A
.jpgwhose bytes are not a real JPEG — HEIC/RAW, or an error body saved as an image — makessharp/libvips throw:Error: Input file contains unsupported image format(sharp)VipsForeignLoad: ".../original.jpg" is not a known file format(vips)The image
indexpath logged that atwarn, so every such cloud file opened one error-hub ticket. 3 duplicates were collapsed into this root (BIT-31438, BIT-31619, BIT-31649).Fix
Detect the format by magic bytes before calling vips (per the 21/10 triage):
isDecodableImage(file)incorrupt-source.tsreads the first 12 bytes and accepts JPEG / PNG / GIF / BMP / TIFF / WebP; anything else (HEIC, RAW, JSON/HTML error bodies, empty files) is rejected.ArchiveService.indexcalls it right after the file is resolved and throwsCorruptSource("unsupported_image_format"). The existing catch (wired by BIT-31621) marks the fileFAILEDonce, logs atinfo, and never reaches the error hub.isCorruptSourceMessageis extended to also match sharp'sInput file contains unsupported image format/unsupported image formatwording, so a decoder failure that slips past the magic-byte check is still classified as source damage rather than a warn.Unreadable files return
truefromisDecodableImageso the existing download/stat flow surfaces the real I/O error instead.Stacking
Stacked on #93 (BIT-31621), which introduced
corrupt-source.tsand wired the image/video catch blocks. Base isfix/BIT-31621-moov-corrupt-source; once #93 merges tomainthis PR auto-retargets and the diff stays a single commit.Verification
vitest run apps/api/src/archive/→ 13 passed, 2 skipped (incl. newisDecodableImagecases: JPEG/PNG/WebP accepted; HEIC, JSON error body, empty rejected).tsc --noEmit -p apps/api→ 0 errors inarchive/(remaining 43 are pre-existing insports/service.ts).Error-loop disposition
Fix is in this branch (not
mainyet); deploy via webhook after merge. Include<!-- paperclip-error-loop-fix-pending-deploy:cluster:202a64490429 -->when closing as done.Paperclip-Issue: BIT-31229
Paperclip-Run: 8b98a125-c9b2-4c2f-b05a-b35054c9eb5b
A .jpg whose bytes are HEIC/RAW or an error body (not a real JPEG) makes sharp/vips throw "Input file contains unsupported image format" / VipsForeignLoad "is not a known file format". The image index path logged that at warn, so every such file opened one error-hub ticket (3 duplicates collapsed into BIT-31229). Detect the format by magic bytes before calling vips: isDecodableImage accepts JPEG/PNG/GIF/BMP/TIFF/WebP and rejects anything else, throwing CorruptSource("unsupported_image_format"). The existing catch (BIT-31621) marks it FAILED once at info and never reaches the error hub. Also extend isCorruptSourceMessage to match sharp's unsupported-format wording, so a decoder failure that slips past the magic bytes is still classified as source damage. Stacked on BIT-31621 (which introduced corrupt-source.ts and wired the image/video catch blocks). Paperclip-Issue: BIT-31229 Paperclip-Run: 8b98a125-c9b2-4c2f-b05a-b35054c9eb5b@cto — Gitea autopilot needs a CTO decision on BitReport.pt/photoreport#94: CI is red on the PR head.
159a0909edf2