sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Unsupported color conversion when trying to convert 200MP heif images taken on S24 Ultra

Open Iaotle opened this issue 10 months ago • 4 comments

Possible bug

  • [x] Running npm install sharp completes without error.
  • [x] Running node -e "require('sharp')" completes without error.
  • [x] I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.
  • [x] Adding sharp.cache(false) does not fix this problem.
  • [x] Using rotate() or keepExif() does not fix this problem.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System:
    OS: Linux 5.15 Debian GNU/Linux trixie/sid
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
    Memory: 53.78 GB / 62.72 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 22.13.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.2 - /usr/local/bin/npm

My apologies in advance if this is not an issue with sharp, though it seems to be either that or configuration, and since I'm not familiar with sharp I thought it would be prudent to ask here, so that I may be directed towards the responsible vendor/package with more info on what's going wrong. I've already looked into libheif, and it seems that the issue does not lie there (see https://github.com/strukturag/libheif/issues/1259). The relevant immich configuration also seems to me to be correct (https://github.com/immich-app/immich/blob/376282e538becf6887504965ac8b3f02ec3389b9/server/src/services/media.service.ts#L202).

What are the steps to reproduce?

Grab heic image with the following dimensions: (200 MP 12240 x 16320 4 MiB). Setup immich using the dockerfile (easy config for reproducing the issue, I already took the step of updating sharp to the latest version manually and that doesn't solve the issue).

Then I get this:

2025-02-19 23:43:02 [Nest] 7  - 02/19/2025, 11:43:02 PM   ERROR [Microservices:JobService] Error: heif: Unsupported feature: Unsupported color conversion (4.3003)
2025-02-19 23:43:02     at Sharp.toBuffer (/usr/src/app/node_modules/sharp/lib/output.js:163:17)
2025-02-19 23:43:02     at MediaRepository.decodeImage (/usr/src/app/dist/repositories/media.repository.js:54:68)
2025-02-19 23:43:02     at MediaService.generateImageThumbnails (/usr/src/app/dist/services/media.service.js:164:63)
2025-02-19 23:43:02     at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
2025-02-19 23:43:02     at async MediaService.handleGenerateThumbnails (/usr/src/app/dist/services/media.service.js:114:25)
2025-02-19 23:43:02     at async JobService.onJobStart (/usr/src/app/dist/services/job.service.js:148:28)
2025-02-19 23:43:02     at async EventRepository.onEvent (/usr/src/app/dist/repositories/event.repository.js:130:13)
2025-02-19 23:43:02     at async Worker.processJob (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:394:28)
2025-02-19 23:43:02     at async Worker.retryIfFailed (/usr/src/app/node_modules/bullmq/dist/cjs/classes/worker.js:581:24)

What is the expected behaviour?

Thumbnail generation should work

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

Docker container should be very easy to set up, and uploading the image should trigger this immediately with no additional setup: https://immich.app/docs/install/docker-compose/

Please provide sample image(s) that help explain this problem

Download the image in question from my share: https://mega.nz/file/r04x1DTD#X8q1hVzAPNfya_ZXizn8HPEOZRFRNRq0DaRpJyX6hwc

Iaotle avatar Feb 19 '25 23:02 Iaotle

I've been able to reproduce and it looks like this relates to libheif security limits (the error message is somewhat misleading).

The unlimited flag provided by sharp and libvips when opening HEIF images currently only removes the security limit on image dimensions, whereas libheif 1.19.0 onwards provides more granular control over these.

I've opened a libvips PR https://github.com/libvips/libvips/pull/4398 to take advantage of this new feature. This change allows me to process the sample image provided locally without error.

lovell avatar Feb 20 '25 15:02 lovell

PR Looks to have been approved / merged, is this supported in the newest version? Running into this error: [Error: Input buffer has corrupt header: source: bad seek to 1986700 heif: Invalid input: Unspecified: Too many auxiliary image references (2.0)] in my lamda using Sharp and heif image and hoping this covers it

kvieira90 avatar May 22 '25 20:05 kvieira90

This issue remains open as the upstream change to libvips will be part of its future v8.17.0 release. Please subscribe to this issue for updates.

lovell avatar May 22 '25 22:05 lovell

Thanks for the quick response, I should have looked at their versions and changelog first.

kvieira90 avatar May 23 '25 11:05 kvieira90

sharp v0.34.3 is now available with prebuilt binaries that include the upstream change to libvips. You'll need to set the unlimited flag to read these images, but please ensure you trust their source before doing so.

lovell avatar Jul 10 '25 08:07 lovell