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

Add duplicate chunk check #334

Merged

Conversation

MichaelMcDonnell
Copy link
Contributor

@MichaelMcDonnell MichaelMcDonnell commented Feb 18, 2022

The duplicate chunk error variant was unused and resulted in a warning when compiling. Only some chunk types are allowed to appear multiple times according to the specification. I have added checks for that. This also fixes the unused variant warning when compiling.

The parse_chunk method is already checking if the info is None so it is safe to unwrap the info in the subsequent parse_* methods.

Ideally the parsing should be refactored at some point so that the parsing methods only receive what they need and not a reference to the whole mutable self. For example, the header, which creates the info, must appear right after the signature. That means that the info could be passed to the subsequent parse_* methods and the they would not need to unwrap it. That would, however, be a large complicated change.

The duplicate chunk error variant was unused and resulted in a warning
when compiling. Only some chunk types are allowed to appear multiple
times according to the [specification](https://www.w3.org/TR/PNG/#5ChunkOrdering).
I have added checks for that. This also fixes the unused variant warning
when compiling.

The `parse_chunk` method is already checking if the info is `None` so it
is safe to unwrap the info in the subsequent `parse_*` methods.

Ideally the parsing should be refactored at some point so that the
parsing methods only receive what they need and not a reference to the
whole mutable self. For example, the header, which creates the info, must
appear right after the signature. That means that the info could be
passed to the subsequent `parse_*` methods and the they would not need
to unwrap it. That would, however, be a large complicated change.
Copy link
Member

@HeroicKatora HeroicKatora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rework of receiving isn't even that appealing to me. There are enough chunks that either have dependencies or conflict on each other or can benefit from having more context information in any case (e.g. gAMA–cHRM–iCCP), various animation related chunks.

I do see value in somehow statically clarifying that the info is available, though.

src/decoder/stream.rs Outdated Show resolved Hide resolved
@HeroicKatora HeroicKatora merged commit bb55a66 into image-rs:master Feb 23, 2022
@MichaelMcDonnell
Copy link
Contributor Author

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants