Skip to content

fix(web): accept TIFF Exif and GPS pointers stored as IFD type 13 - #41526

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
only21mil:fix/web-tiff-exif-ifd-type13
Nov 23, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
only21mil:fix/web-tiff-exif-ifd-type13

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

When previewing a TIFF whose Exif or GPS pointer is stored as the standard IFD type (type 13) in the Files panel, the preview fails with "Unable to load image." libtiff, Adobe tools and other TIFF writers can store the ExifIFD (34665) and GPSIFD (34853) pointers this way (Adobe TIFF Technical Note 1).

validateTiffMetadata in imageDecode.worker.ts only accepts these two pointers as type 4 (LONG), so it rejects the file with tiff-metadata-pointer before the decoder runs. #41228 already taught the validator's type table about type 13 for SubIFDs, but this pointer check was left at type 4. The tiff decoder itself skips type-13 entries and decodes the image normally.

Change

The pointer check now accepts type 4 or type 13, still with exactly one value. The pointed IFD is validated exactly as before (bounds, depth, entry and allocation limits). Any other type or a count other than 1 is still rejected.

Scope

One condition in imageDecode.worker.ts, plus the existing WhiteIsZero TIFF case in AttachmentFilePreview.browser.test.tsx. It needs no issue because it is a small fix for an obvious bug: a valid TIFF fails to preview. SubIFDs and InteropIFD have no pointer-type check, so they already accept type 13. The desktop favicon reader's Exif orientation lookup (JPEG only) is a separate surface and is not touched.

Verification

An AI agent (T3 Code Nightly) ran each check below.

  • AttachmentFilePreview.browser.test.tsx: the WhiteIsZero TIFF case now adds a type-13 ExifIFD entry to its fixtures and checks that a SHORT pointer and a two-value pointer are still rejected. On 593885bd5df it fails with Error: Invalid TIFF metadata pointer.; on this branch it passes. vp run check:changed passes.

  • Real app, web client in Linux Chromium, fresh isolated dev data on each commit, no accounts needed.

    Setup: vp run dev --no-seed, a project folder holding a 64×64 RGB TIFF whose ExifIFD pointer (34665) is type 13 and points at an Exif IFD. Pillow reads the pointer and its Exif IFD, and tiff@7.1.3 decodes the image.

    Steps: open the project → Files panel → click the .tiff.

    593885bd5df (before) 437027d9c47 (after)
    The preview shows "Unable to load image." instead of the TIFF. The 64 x 64 TIFF renders: an orange square on a black tile.
    The preview shows "Unable to load image." The decode worker reports tiff-metadata-pointer. The 64 × 64 TIFF renders: an orange square on a black tile.

    Pixels read back from the rendered preview after the fix: corner [5,5,5,255] and center [255,159,10,255], matching the file.

Fixture script (Node, no dependencies): node make-exif-ifd-tiff.mjs out.tiff
import { writeFileSync } from "node:fs";

const out = process.argv[2];
if (!out) throw new Error("usage: node make-exif-ifd-tiff.mjs <out.tiff>");

const SHORT = 3, LONG = 4, UNDEFINED = 7, IFD = 13;
const W = 64, H = 64;
const ifdSize = (n) => 2 + n * 12 + 4;
const IFD0 = 8;
const BPS = IFD0 + ifdSize(11); // 146
const EXIF = BPS + 6; // 152
const PIXELS = EXIF + ifdSize(1); // 170
const buffer = new ArrayBuffer(PIXELS + W * H * 3);
const view = new DataView(buffer);
const bytes = new Uint8Array(buffer);

view.setUint16(0, 0x4949);
view.setUint16(2, 42, true);
view.setUint32(4, IFD0, true);
[8, 8, 8].forEach((bits, i) => view.setUint16(BPS + i * 2, bits, true));

function writeIfd(offset, entries) {
  view.setUint16(offset, entries.length, true);
  entries.forEach(([tag, type, value, count = 1], index) => {
    const entry = offset + 2 + index * 12;
    view.setUint16(entry, tag, true);
    view.setUint16(entry + 2, type, true);
    view.setUint32(entry + 4, count, true);
    if (type === UNDEFINED) bytes.set(value, entry + 8);
    else if (type === SHORT && count === 1) view.setUint16(entry + 8, value, true);
    else view.setUint32(entry + 8, value, true);
  });
  view.setUint32(offset + 2 + entries.length * 12, 0, true);
}

writeIfd(IFD0, [
  [256, SHORT, W],
  [257, SHORT, H],
  [258, SHORT, BPS, 3], // BitsPerSample 8,8,8, stored out of line
  [259, SHORT, 1],
  [262, SHORT, 2],
  [273, LONG, PIXELS],
  [277, SHORT, 3],
  [278, SHORT, H],
  [279, LONG, W * H * 3],
  [284, SHORT, 1],
  [34665, IFD, EXIF], // ExifIFD stored as type 13
]);
writeIfd(EXIF, [[0x9000, UNDEFINED, [...new TextEncoder().encode("0232")], 4]]); // ExifVersion

// Orange square on a near-black field.
for (let y = 0; y < H; y++)
  for (let x = 0; x < W; x++) {
    const inside = x >= 16 && x < 48 && y >= 16 && y < 48;
    bytes.set(inside ? [0xff, 0x9f, 0x0a] : [0x05, 0x05, 0x05], PIXELS + (y * W + x) * 3);
  }

writeFileSync(out, bytes);

Generated with Gemini 4 Neon in T3 Code Nightly

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 437027d and 325257c.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The TIFF metadata validator now accepts type-13 pointers with a value count of 1. Browser tests add ExifIFD metadata fixtures and check invalid pointer types, counts, and oversized or truncated metadata.

Changes: TIFF Pointer Validation

Layer / File(s) Summary
Pointer validation and ExifIFD test coverage
apps/web/src/components/files/imageDecode.worker.ts, apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
The validator accepts pointer types 4 and 13 when the value count is 1. Tests add type-13 ExifIFD pointers and check invalid pointer types, counts, and oversized or truncated metadata.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: maria-rcks

Merge Risk: Minimal · previous review 43702

TIFF previews with Exif or GPS pointers stored as type 13 should now load instead of showing "Unable to load image." Invalid pointer types and counts are still rejected. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(web): accept TIFF Exif and GPS pointers stored as IFD type 13" states the primary change. The raw summary shows imageDecode.worker.ts now accepts type 13 for TIFF pointer tags with a co…
Description check Passed The description follows the template. It has Problem, Change, Scope, and Verification sections, and each contains specific content. The Problem explains the expected and actual behavior with the TIFF …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(web): accept TIFF Exif and GPS pointers stored as IFD type 13" states the primary change. The raw summary shows imageDecode.worker.ts now accepts type 13 for TIFF pointer tags with a count of 1, and the test file covers the Exif pointer case. The title is specific, follows the conventional commit style, and matches the objectives. It is slightly narrower than the full change because it names Exif and GPS, while the summary mentions only the pointer check generally; this is a minor point.

Full details: Description check

Explanation

The description follows the template. It has Problem, Change, Scope, and Verification sections, and each contains specific content. The Problem explains the expected and actual behavior with the TIFF type 13 pointer and the tiff-metadata-pointer error. The Change explains the type 4 or type 13 acceptance with count 1. The Scope names the touched files, explains why no issue is linked, and notes the out-of-scope favicon reader. Verification gives the failing and passing test results, the Linux Chromium real-app steps, before and after evidence, and pixel values. The description has a minor gap: the Scope section does not link an issue, but it gives a reason for the lack of one, as the template allows for small obvious bugs. The template's agent attribution line is present.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 77c230e and 437027d.

Files selected for processing: 2

  • apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
  • apps/web/src/components/files/imageDecode.worker.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 23, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Seed the same synthetic TIFF project and Replay thread on each commit, open Files, and select exif-type13.tiff. Web browser, fresh isolated state, light theme, 1440×1000.

Before After
856b105fa2 325257cc08
Before: type-13 ExifIFD TIFF displays Unable to load image After: type-13 ExifIFD TIFF renders the orange square at 64 × 64

Scenario and TIFF generator. Before recording · After recording.

The scenario runner exited 0: failed on base and passed on head.

Not shown:

  • GPSIFD type-13 pointers and rejection of invalid pointer types, counts, or metadata were not exercised in the real app; this scenario covers the reported ExifIFD rendering failure.
  • The type-4 control TIFF was generated but not opened in this scenario.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 23, 2026
@juliusmarminge
juliusmarminge merged commit 9fae2cc into pingdotgg:main Nov 23, 2026
56 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants