-
Notifications
You must be signed in to change notification settings - Fork 11
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
Handling invalid, unknown ancillary chunks #320
Comments
This is a good question, and perhaps the specification could be clarified to make finding the answer more obvious. However, a little digging clarified the issue and 13.1 Error handling is clear:
and this is further clarified in 5.3 Chunk layout:
Thus, for any arbitrary chunk type considered as a 32-bit unsigned integer in network byte order, the decoder:
If the chunk is ancillary and the chunk is unknown, no further processing is required; the chunk can be ignored. If the chunk is critical and is not known, that is a fatal error. Libpng is clearly incorrect in reporting a fatal error. The restriction of registered chunk types to the upper and lowercase ASCII letters is a convenience when examining a PNG datastream, for example with a hex editor, but does not affect processing:
So in practice this just means that the PNG specification will not register chunk types containing numbers, control characters, etc. |
We should definitely add that to the test suite as it shows an interop issue. |
Because we got multiple reports of this from in-the-wild files I wrote a patch for Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1873422 that I plan to land shortly (in the 125 cycle). I can't access the poc link in the above comment but I expect the patch to change Firefox to display the image like Chrome. |
A bit of testing reveals: pngcheck gives an error and stops
pngcrush gives an error, halts, and does not create an output file (even with
Firefox Nightly 125 displays an error (as an image :) ) Chrome Canary 123 displays the image TweakPNG gives an error, warns about a corrupted file, and displays only the chunks before the error PNG format inspector displays the data without comment, but is basically a lightly-structured hex displayer anyway PNG file chunk inspector gives a red error, but displays the invalid chunk and all other chunks correctly. (I don't have access to a Mac currently so no Safari test) pngcp from pngtools errors out because of libpng:
|
@tnikkel great. I'm working on a WPT that uses this file (and a copy with the invalid chunk deleted, as the reference) |
Yeah, I could be mistaken but when I looked the invalid chunk type seemed to put libpng into a terminal error state, so the invalid chunk type is only ignored if it comes after we have image data. |
wpt results for recovery from unknown and invalid ancillary chunk On 29 Feb 2024: Chrome 124 and Edge 123 pass, Firefox 125 and Safari TP 189 fail. |
The invalid chunk comes before the image data in that testcase, so that is what I would expect from that testcase. |
@ProgramMax could you review web-platform-tests/wpt#44936 please? It is the same as the other error-recovery test, but the invalid ancillary chunk is after |
WPT results show interop on error recovery for ancillary chunks after |
Originally raised by DLiang Fun:
The text was updated successfully, but these errors were encountered: