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

Regression in v0.32.0: flip operation can cause "out of order read" error #3600

Closed
3 tasks done
jwerre opened this issue Mar 24, 2023 · 2 comments
Closed
3 tasks done

Comments

@jwerre
Copy link

jwerre commented Mar 24, 2023

Possible bug

I've run into and issue where when I try to flip an image I get the following error:

Error: pngload_buffer: out of order read at line 1102

I've tried other transformations (including flop) on the same image without issues.

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.

npm view sharp dist-tags.latest
0.32.0

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

Ok to proceed? (y)

System:
OS: Linux 5.15 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (5) arm64 unknown
Memory: 9.80 GB / 11.68 GB
Container: Yes
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 16.18.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.19.2 - /usr/local/bin/npm

I'm running this inside the node:16.18-slim Docker container

What are the steps to reproduce?

const processImage = async function (buffer, options = {}) {

	const image = sharp(buffer);

	for (const key of Object.keys(options)) {
		const val = options[key];
		if (val && typeof image[key] === 'function') {
			image[key](val);
		}
	}

	let result;

	try {
		result = await image.toBuffer();
	} catch (err) {
		console.log(err); // Error: pngload_buffer: out of order read at line 1102
		throw err;
	}

	return result;
	
};


const file = readFileSync('./test/assets/test_img.png');
const floppedBuff = await processImage(file, {flop: true}); // OK
const flippedBuff = await processImage(file, {flip: true}); // ERROR

What is the expected behaviour?

Flipped image should not produce an error.

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

See above.

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

test_img

@jwerre jwerre added the triage label Mar 24, 2023
@lovell
Copy link
Owner

lovell commented Mar 24, 2023

Thanks for reporting, this will be a side effect of the switch in the newly-released v0.32.0 to more eagerly taking advantage of libvips' sequential read feature. We need to add flip to the list of operations that will force the pipeline as a whole to use random access read instead.

sharp/src/pipeline.cc

Lines 1655 to 1670 in b9d4c30

// Force random access for certain operations
if (baton->input->access == VIPS_ACCESS_SEQUENTIAL) {
if (
baton->trimThreshold > 0.0 ||
baton->normalise ||
baton->position == 16 || baton->position == 17 ||
baton->angle != 0 ||
baton->rotationAngle != 0.0 ||
baton->tileAngle != 0 ||
baton->useExifOrientation ||
baton->claheWidth != 0 ||
!baton->affineMatrix.empty()
) {
baton->input->access = VIPS_ACCESS_RANDOM;
}
}

For this sample image, it looks like the PNG decoder simply can't deliver pixel values quickly enough to libvips' very fast flip operation, whereas the flop operation is slower so it still works.

You can work around it for now with:

sharp(input, { sequentialRead: false }).flip()...

@lovell lovell added bug and removed triage labels Mar 24, 2023
@lovell lovell added this to the v0.32.1 milestone Mar 24, 2023
@lovell lovell changed the title flip causes Error: pngload_buffer Regression in v0.32.0: flip operation can cause "out of order read" error Mar 24, 2023
@lovell
Copy link
Owner

lovell commented Apr 27, 2023

v0.32.1 now available.

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

2 participants