Skip to content

[0.84] Cherry pick: fix(metro): vendor image dimension parsing (#1860) - #1870

Merged
robhogan merged 1 commit into
0.84.xfrom
robhogan/0.84/image-size
Aug 19, 2026
Merged

robhogan merged 1 commit into
0.84.xfrom
robhogan/0.84/image-size

Conversation

@robhogan

Copy link
Copy Markdown
Collaborator

Picks #1860 into 0.84 stable branch (RN 0.85 and 0.86)

Summary:

  • replace the image-size dependency with an in-tree parser for the image formats Metro supports
  • dispatch by the declared asset type rather than running unrelated format detectors
  • preserve CgBI PNG, SVG units/viewBox, TIFF endianness, WebP variants, and KTX1/KTX2 support
  • reuse the first asset buffer already read for hashing
  • reject truncated, mismatched, non-positive, and non-advancing malformed inputs

This removes image-size and its queue dependency without introducing a new third-party package. The parser is derived from the MIT-licensed image-size format support, with its notice retained inline and bounds/forward-progress checks added throughout.

Refs #1762
Refs #1800

Pull Request resolved: #1860

Test Plan:

  • yarn flow check
  • yarn typecheck-ts
  • yarn lint
  • yarn build
  • node node_modules/jest/bin/jest.js packages/metro/src/lib/__tests__/imageSize-test.js packages/metro/src/__tests__/Assets-test.js --runInBand --no-watchman
  • full Jest run: 141 suites passed; the two Watchman integration suites failed because the local environment cannot chmod the shared Watchman state directory
  • checked all applicable fixtures from the upstream image-size corpus
  • exercised 100,000 randomized malformed buffers across all parsers

Changelog: [Fix] Remove the image-size dependency and parse supported image dimensions within Metro.

Test plan

Patched into an Expo app and verified Metro extracts the same sizes as it did with image-size for a test image in every supported format.

Summary:
- replace the `image-size` dependency with an in-tree parser for the image formats Metro supports
- dispatch by the declared asset type rather than running unrelated format detectors
- preserve CgBI PNG, SVG units/viewBox, TIFF endianness, WebP variants, and KTX1/KTX2 support
- reuse the first asset buffer already read for hashing
- reject truncated, mismatched, non-positive, and non-advancing malformed inputs

This removes `image-size` and its `queue` dependency without introducing a new third-party package. The parser is derived from the MIT-licensed `image-size` format support, with its notice retained inline and bounds/forward-progress checks added throughout.

Refs #1762
Refs #1800

Pull Request resolved: #1860

Test Plan:
- `yarn flow check`
- `yarn typecheck-ts`
- `yarn lint`
- `yarn build`
- `node node_modules/jest/bin/jest.js packages/metro/src/lib/__tests__/imageSize-test.js packages/metro/src/__tests__/Assets-test.js --runInBand --no-watchman`
- full Jest run: 141 suites passed; the two Watchman integration suites failed because the local environment cannot chmod the shared Watchman state directory
- checked all applicable fixtures from the upstream `image-size` corpus
- exercised 100,000 randomized malformed buffers across all parsers

Changelog: [Fix] Remove the image-size dependency and parse supported image dimensions within Metro.

Reviewed By: huntie

Differential Revision: D116437966

Pulled By: javache

fbshipit-source-id: 9f88b14668ae863b22a4aaf91b1298967c7f07c1
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 19, 2026
@robhogan
robhogan changed the base branch from main to 0.84.x August 19, 2026 14:07
@robhogan
robhogan merged commit 06e9e17 into 0.84.x Aug 19, 2026
2 of 3 checks passed
@robhogan
robhogan deleted the robhogan/0.84/image-size branch August 19, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant