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

WebP encoder sometimes creates invalid WebP files #2171

Closed
KenyC opened this issue Mar 18, 2024 · 2 comments
Closed

WebP encoder sometimes creates invalid WebP files #2171

KenyC opened this issue Mar 18, 2024 · 2 comments

Comments

@KenyC
Copy link

KenyC commented Mar 18, 2024

The following code produces an 4x4 RGBA image filled with blank pixels in both webp and png format.

use image::{ImageBuffer, Rgba};

fn main() {

	let width = 4;
	let height = 4;
	let data = vec![0; width * height * 4];

	let image : ImageBuffer<Rgba<u8>, Vec<u8>> = ImageBuffer::from_vec(
		width as u32, height as u32, 
		data
	).unwrap();

	let mut image_file = std::fs::File::create("/tmp/test.webp").unwrap();
	image.write_to(&mut image_file, image::ImageFormat::WebP).unwrap();

	let mut image_file = std::fs::File::create("/tmp/test.png").unwrap();
	image.write_to(&mut image_file, image::ImageFormat::Png).unwrap();
}

Expected

The code runs without panic and produces the desired two files. Both files can be opened by external image viewers.

Actual behaviour

The code runs without panic and does produce the desired two files. But the webp image cannot be opened by image viewers (tried Gwenview and Firefox). The png on the other hand opens without issues.

Reproduction steps

See above.

Observations:

  • changing the width to 100 fixes the problem
  • problem persists if all bytes are set to 0xff
@fintelia
Copy link
Contributor

This is probably caused by image-rs/image-webp#56. Just published a new release of image-webp which should have the fix

@Shnatsel
Copy link
Contributor

I've written a fuzzing harness to test for issues like these. It does appear to be fixed, or at least my fuzz harness doesn't turn up any issues.

I'll open a PR with it once I add RGB support (not just RGBA) and more checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants