Skip to content

[0.83] fix(metro): vendor image dimension parsing (#1860) - #1871

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

[0.83] fix(metro): vendor image dimension parsing (#1860)#1871
robhogan merged 1 commit into
0.83.xfrom
robhogan/0.83/image-size

Conversation

@robhogan

Copy link
Copy Markdown
Collaborator

Cherry-pick #1860 to 0.83

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.

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 merged commit 809c36d into 0.83.x Aug 19, 2026
16 checks passed
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