-
Notifications
You must be signed in to change notification settings - Fork 145
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
Treat most auxiliary chunk errors as benign. #569
Conversation
FWIW, I mostly just went through
The list above doesn't describe all the changes in this PR, but it should hopefully help provide the high-level context for the changes. |
Not sure if I can/should say in the commit descriptions that it fixes #525. Probably not yet, because we may still need to do something for |
I think I was incorrect above. The errors above are avoidable - we can ignore the whole chunk if enum parsing fails. There may also be other options - e.g. extending the enum with an "unknown" value (this would be a breaking change), or marking it with the |
src/decoder/stream.rs
Outdated
Err(DecodingError::Format( | ||
FormatErrorInner::DuplicateChunk { kind: chunk::pHYs }.into(), | ||
)) | ||
if !self.have_idat && info.pixel_dims.is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the if
and else
blocks are swapped here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. Thanks for catching this. Let me fix this change when rebasing on top of the tip-of-tree.
I'll write a note to myself to try to improve unit test coverage for auxiliary chunks. (Sadly I am not sure if I'll have time for it this week, but I'll keep it in my to-do list.)
843f55a
to
598fbd3
Compare
Force push above is primarily to rebase and resolve merge conflicts that arose from #568, but also to:
Hmmm... let me figure out which button to press to flush my "pending" review replies/comments... |
src/decoder/stream.rs
Outdated
Err(DecodingError::Format( | ||
FormatErrorInner::DuplicateChunk { kind: chunk::pHYs }.into(), | ||
)) | ||
if !self.have_idat && info.pixel_dims.is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops. Thanks for catching this. Let me fix this change when rebasing on top of the tip-of-tree.
I'll write a note to myself to try to improve unit test coverage for auxiliary chunks. (Sadly I am not sure if I'll have time for it this week, but I'll keep it in my to-do list.)
src/decoder/stream.rs
Outdated
return Err(DecodingError::Format( | ||
FormatErrorInner::OutsidePlteIdat { kind: chunk::tRNS }.into(), | ||
)); | ||
if info.palette.is_some() || !self.have_idat { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserving the old conditions requires saying &&
instead of ||
: info.palette.is_some() && !self.have_idat
. I'll fix this when rebasing... :-/
@fintelia, can you PTAL again? |
Sorry, been meaning to get a chance to do another review pass. One thing I've been wanting to consider is whether it would be cleaner to have all the chunk parsing functions continue to report errors, but have |
No worries, thanks for getting back to this.
I see. This way Rust I'll try to tweak this PR to reintroduce the errors (and once that's done, I'll give a heads up to ask for another review pass). |
4ed7a50
to
8986871
Compare
Ok, I think this is ready for another review please.
|
Ugh... right after I pressed the "comment" / "send" button I realized that there are some fuzzing failures... let me take a look... |
8986871
to
04905ae
Compare
This commit is based on what `png_handle_...` functions do in `libpng/pngrutil.c`: * Chunks appearing before IHDR are a fatal error. `png` crate already detects this in a single, centeralized location and reports `ChunkBeforeIhdr` error. * Chunks appearing after IDAT chunk, or duplicated chunks are treated as a benign error and ignored. Note that there are some places where `png` crate is more permissive than `libpng`, for example `parse_...` functions in general don't complain if the chunk is longer than necessary.
04905ae
to
b1c1253
Compare
Ok, this is now fixed. I missed that |
Thanks! |
This commit is based on what
png_handle_...
functions do inlibpng/pngrutil.c
:png
crate already detects this in a single, centeralized location and reportsChunkBeforeIhdr
error.Note that there are still some places where
png
crate is more strict. In some places this is unavoidable - e.g. theSrgbRenderingIntent
enum can't represent values greater than 3 and theUnit
enum can't represent values greater than 1. There are also some places wherepng
crate is more permissive - e.g. in generalparse_...
functions don't complain if the chunk is longer than necessary.