AldaronLau / png_pong

A pure Rust PNG image decoder and encoder based on lodepng.

Home Page:https://docs.rs/png_pong

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iTxt encode function does not encode the size of the "val" creating incorrectly sized chunk

mauricefisher64 opened this issue · comments

Describe the bug
The size of the iTxt encoded box will be incorrect since the val field is not included.

To Reproduce
Here is an example of code that does not work correctly:

// make XMP chunk
let mut xmp_data = Vec::new();
let mut xmp_encoder = png_pong::Encoder::new(&mut xmp_data).into_chunk_enc();

            let mut xmp_chunk = png_pong::chunk::Chunk::InternationalText(InternationalText {
                key: XMP_KEY.to_string(),
                langtag: "".to_string(),
                transkey: "".to_string(),
                val: updated_xmp,
                compressed: false,
            });
            xmp_encoder
                .encode(&mut xmp_chunk)
                .map_err(|_| Error::EmbeddingError)?;

The size of xmp_data will be short by the length of updated_xmp.

The cause of the issue in the InternationText::write function. It does not include the size of "val" in the prepare statement:
// Encode
enc.prepare(
self.key.len() + self.langtag.len() + self.transkey.len() + 5,
consts::ITEXT,

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@mauricefisher64 Thanks for opening this issue! I can work on fixing it, unless you have a fix ready.

@AldaronLau I work with @mauricefisher64. If you can create and release a fix, that would be greatly appreciated!

I would fix it but I am on vacation for the next 7 weeks :) Thanks for handling this, your PNG library is the only one I could find that presents the structure information we need.

Just released a new version to crates.io, with the patch. Let me know if there's any more issues!

Thank you!