Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"out of order read" when combining normalise() with composite() #3669

Closed
3 tasks done
jamiemill opened this issue May 15, 2023 · 5 comments
Closed
3 tasks done

"out of order read" when combining normalise() with composite() #3669

jamiemill opened this issue May 15, 2023 · 5 comments

Comments

@jamiemill
Copy link

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

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

  System:
    OS: macOS 13.3
    CPU: (8) arm64 Apple M2
    Memory: 88.88 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
    npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
    Watchman: 2023.05.08.00 - /opt/homebrew/bin/watchman
  npmPackages:
    sharp: ^0.32.1 => 0.32.1 

What are the steps to reproduce?

const sharp = require("sharp");

const img = sharp("image.png")
  .normalise()
  .composite([{ input: "watermark.png" }])
  .toFile("output.jpg");

throws error:

pngload: out of order read at line 79

and writes a zero byte image.

If I comment out either the composite() or normalise() step, it works fine. But it fails when both are used together.

It works if I downgrade to 0.31.3, so it could be related to #3600 (comment)

What is the expected behaviour?

Expect to see the image.jpg overlaid with watermark.png.

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

See the code snippet above, and test it with the images below.

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

image
watermark

@lovell lovell added bug and removed triage labels May 15, 2023
@lovell
Copy link
Owner

lovell commented May 15, 2023

Hi, yes, this will be related to defaulting to sequential read in v0.32.0.

When the normalise() operation is used, sharp switches libvips into random access read for the input as sequential read is unsupported. However it should also be doing this for all of the composite() operation input(s) to match.

You should be able to workaround this for now via:

-   .composite([{ input: "watermark.png" }])
+   .composite([{ input: "watermark.png", sequentialRead: false }])

@lovell lovell added this to the v0.32.2 milestone May 15, 2023
@jamiemill
Copy link
Author

Thanks, that indeed fixes my test case. But in my real code, I'm using typescript and I get:

TSError: ⨯ Unable to compile TypeScript:
index.ts:5:41 - error TS2322: Type '{ input: string; sequentialRead: false; }' is not assignable to type 'OverlayOptions'.
  Object literal may only specify known properties, and 'sequentialRead' does not exist in type 'OverlayOptions'.

5   .composite([{ input: "watermark.png", sequentialRead: false }])

@lovell
Copy link
Owner

lovell commented May 16, 2023

Commit de0fc07 fixes the original access method problem, and commit 3340120 ensures the type definitions for composite include all the underlying input options, which includes sequentialRead.

A workaround for TypeScript might be something like (untested):

-   .composite([{ input: "watermark.png" }])
+   .composite([{ input: "watermark.png", sequentialRead: false } as unknown as OverlayOptions])

Thanks for reporting this, the changes will be in v0.32.2.

@adityapatadia

This comment was marked as off-topic.

@lovell
Copy link
Owner

lovell commented Jul 11, 2023

v0.32.2 now available.

@lovell lovell closed this as completed Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants