-
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
base: master
Are you sure you want to change the base?
Conversation
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 still some places where `png` crate is more strict. In some places this is unavoidable - e.g. the `SrgbRenderingIntent` enum can't represent values greater than 3 and the `Unit` enum can't represent values greater than 1. There are also some places where `png` crate is more permissive - e.g. in general `parse_...` functions don't complain if the chunk is longer than necessary.
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 |
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?
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.