Skip to content
New issue

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

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

Already on GitHub? # to your account

read_until_image_data doesn't seem to read until an IDAT #559

Open
PatD123 opened this issue Dec 28, 2024 · 4 comments
Open

read_until_image_data doesn't seem to read until an IDAT #559

PatD123 opened this issue Dec 28, 2024 · 4 comments

Comments

@PatD123
Copy link

PatD123 commented Dec 28, 2024

I basically copied all the bytes of a png into another file (.pnle which is just smth i made up for a temp file). So technically up until the first IDAT chunk, all the metadata before should 100% be right.

I open the .pnle using png::Decoder to get a decoder object, then i call decoder.read_info(), which according to the spec and the src code, should read until the first IDAT. However, i truncate my .pnle a little bit towards the end, but all the metadata before the first IDAT is untouched. When the read_info func is called, it errors out giving me a MissingImageData inner error. Only, when i have the full entire png in the pnle does the read_info func complete.

In the Decoder src, read_info() calls read_until_image_data() and everytime it crashes saying that it's reached Decoded::ImageEnd already, which is only returned in stream.rs if it's found IEND.

@fintelia
Copy link
Contributor

Are you sure you didn't entirely remove the IDAT chunks? The decoder can't know it has reached the image data until it sees a chunk with type=IDAT. If it hits the end of the input first it'll return a MissingImageData error.

@PatD123
Copy link
Author

PatD123 commented Dec 30, 2024

@fintelia Im doing this (basically the example usage for this crate):

let encoder = png::Encoder::with_info(w, img_info)?;
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(data);

But im not fully writing down all the data. If i do &data[..data.len()-1], it doesn't seem to work but there should at least be a single IDAT? Or am i misunderstanding an IDAT or something?

I was just looking for a function that could parse all the ihdr chunks and pallete, everything not including the data.

@fintelia
Copy link
Contributor

I'd have to look into the implementation of write_image_data to be sure, but I think the writer might wait to write an IDAT until it has enough data buffered and/or a full frame worth of data has been written.

@PatD123
Copy link
Author

PatD123 commented Dec 30, 2024

ok interesting thanks!

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

No branches or pull requests

2 participants