Repository navigation
Conversation
storeAttachment rejected HEIC/HEIF with a 400 and stored TIFF and BMP verbatim, although neither Chromium nor the providers read those formats. The server now decodes them (libheif WASM via heic-decode, utif2, and a small BMP reader), and stores a JPEG, or a PNG when the image has transparency, under the original name with the new extension. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Thanks for the pull request, @Navipro70. It was closed automatically because it does not meet the requirements below yet. This is an automated check, not a review of the change. Contributor approval. bb reviews pull requests only from approved contributors, and you are not on the list yet. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to your pull request, and explain what it changes and why. A maintainer then adds you to the list and reopens the pull request. See CONTRIBUTING.md for details. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f18069ed3f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| UTIF.decodeImage(buffer, page); | ||
| checkedDimensions(page.width, page.height); |
There was a problem hiding this comment.
Check HEIF/TIFF dimensions before decoding pixels
For a highly compressed HEIF/TIFF that is below 35MB but expands beyond 64 megapixels, the dimension limit is checked only after the decoder has allocated and decompressed the image. TIFF calls UTIF.decodeImage first, and decodeHeifImage likewise validates only after decodeHeif returns its RGBA buffer. Consequently, an oversized upload can exhaust server memory before reaching the intended rejection. Validate metadata dimensions or enforce a decoder allocation limit before decoding pixels.
Useful? React with 👍 / 👎.
| image.data.byteOffset, | ||
| image.data.byteLength, |
There was a problem hiding this comment.
Enforce JPEG's per-axis dimension limit before encoding
An opaque 65,536×1 BMP is only 196,662 bytes and passes both the attachment-size and megapixel checks, so it reaches this JPEG encoder unchanged. JPEG frame dimensions are limited to 16 bits, however, so that width cannot be represented in the output. Such an upload must be rejected with a conversion error or encoded as PNG rather than proceeding through the JPEG path with unrepresentable dimensions.
Useful? React with 👍 / 👎.
| const maskOffset = BMP_FILE_HEADER_BYTES + 40; | ||
| const hasAlphaMask = headerSize >= 56 || compression === BI_ALPHABITFIELDS; | ||
| return { | ||
| red: view.getUint32(maskOffset, true), |
There was a problem hiding this comment.
Bounds-check external BMP masks before reading them
A truncated 16/32-bit BI_BITFIELDS BMP can contain a complete 40-byte DIB header but none of the external masks—for example, a 54-byte file. It passes the header checks, then this read throws a RangeError rather than an ImageConversionError. Since normalizeUploadedImage rethrows errors outside that class, the upload returns a generic HTTP 500 instead of the intended actionable HTTP 400. Check that all required masks are present or normalize BMP decoder failures as the TIFF decoder does.
Useful? React with 👍 / 👎.
A content script converts these attachments with macOS sips before BB uploads them, and steps aside per format once BB converts it itself (get-bb/bb#1670, get-bb/bb#8349). Co-authored-by: Claude Opus 5.5 <[email protected]>
Human comments
What was wrong
storeAttachment(apps/server/src/services/projects/attachments.ts) refusedimage/heicandimage/heifuploads with a 400 because nothing downstream can read them: Chromium/Electron has no HEIC decoder and the providers only accept JPEG, PNG, GIF and WebP. Photos from an iPhone could not be attached at all. TIFF and BMP had the same root problem but were stored verbatim aslocalImage, so the agent received an image type its provider cannot read. See #1670 and its reproduction report.What changed
apps/server/src/services/projects/attachment-image-conversion.ts, following the fix proposed in HEIC images aren't rendered in the UI #1670: at the upload boundary,image/heic,image/heif(and the-sequencevariants),image/tiffandimage/bmp(x-bmp,x-ms-bmp) are decoded to RGBA and re-encoded as JPEG (quality 90), or as PNG when any pixel is transparent.heic-decode(libheif compiled to WASM; the WASM is inlined in its JS, so the esbuild server bundle needs no extra assets). It honours the HEIF rotation/mirror transforms.utif2(pure JS), first page.jpeg-js. PNG encoding usesnode:zlib.storeAttachmentstores the converted bytes under the original name with a.jpgor.pngextension, and returns that name,mimeTypeandsizeBytes. The 35MB limit is checked before and after conversion. An image that fails to decode, or is over 64 megapixels, gets a 400Could not convert <name> to JPEG or PNG: <reason>. HEIF and TIFF dimensions are read from metadata and checked before any pixels are decoded, which bounds memory. Any decoder exception becomes this 400 rather than a 500. An opaque image wider or taller than JPEG's 65,535 px limit is written as PNG..heicuploaded asapplication/octet-streamis still kept as alocalFile.bb guide projectstext now describes the conversion instead of the rejection.Things to weigh:
libheif-jsis LGPL-3.0 and adds about 2.4MB tostart-server.js.@jsquash/avif) load a separate.wasmfile that the server bundle does not ship today. I'm happy to follow up if you want it.How you verified
attachment-image-conversion.test.ts(25): real HEIC/TIFF/BMP fixtures made with macOSsips(plus hand-built 24-bit and 8-bit palette BMPs) decode back to the expected pixel gradient. Transparent inputs come out as PNG with their alpha kept. Corrupt input raisesImageConversionError. The megapixel cap holds, including a 100,000×100,000 TIFF header rejected before decoding. A truncated BITFIELDS BMP gives a 400, and a 65,536×1 BMP comes out as PNG. The last three follow the Codex review.test/public/public-project-attachments.test.ts: the HEIC rejection test is replaced by an upload through the public route for HEIC, HEIF with alpha, TIFF and BMP. Each returns 201 with alocalImage.jpg/.pngDTO, and its content route serves the converted bytes with the new content type. A corrupt HEIC still gets a 400, and an octet-stream.heicstays a file. Onmainthe new upload test fails with 400.pnpm exec turbo run test --filter=@bb/server -- <the three attachment test files>: 45 passed.pnpm exec turbo run typecheck lint lint:type-aware --filter=@bb/server: passes.scripts/build-node-entry.mjsand ran the bundle on a 4032×3024 HEIC (469ms) and TIFF (351ms).Fixes #1670