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
Allow a zero sized iCCP chunk. #97
Conversation
Rebased and simplified the changes after the introduction of |
The relevant spec is here: When taking the spec really really literally, it does say: I agree that the current code is not great due to not handling this issue separately (but returning an error due to an allocation check instead). It could return it as a separate error (maybe with error code 100, or with a new code), or allow the 0-length ICC profiles. Whether 0-length ICC chunk should actually be allowed is a different issue though. Do you have a use case or know existing cases where such chunks occur? Thank you :) P.S. since the code to read the iCCp chunk was based on the code to read zTXt chunks, zTXt chunks are likely giving the same error, and so are iTXt and tEXt chunks, I didn't test it yet but probably they wouldn't support it, and for text chunks the spec does say explicitly that 0 lengths should be allowed. So those must be fixed for sure (if they're indeed broken), thanks for finding this! |
The spec says the profile conforms to ICC (without "must"), but due to its usage of the words "must" after that for RGB or GREY profile, I'd say, best to handle it as an error, unless you know there are use cases that need it. Would you like to change the merge request to make this case return e.g. error 100? |
Ah I misread the API to be a key-value pair style thing with names as the keys and profile data as the values, so I assumed it was extensible and a client could add new names as they wanted which may not necessarily have had a sized profile. Your explanation clears things up, thanks! I don't have any examples as I only spotted this since it was right next to the Also looking at the uses of |
Previously this had the potential to return an allocation error if the return value from malloc(0) was NULL, otherwise it would have returned success. The return value of malloc(0) shouldn't cause behavioural differences in a program, and thankfully in this case a zero sized ICC profile is invalid, so return an error about that instead.
Thanks! You're right about addChunk_tIME, I'll reduce some allocations soon |
This fixes
two issuesone issue:2) A memcpy() with a nullptr as the source or destination is undefined behaviour, even if the length to copy is zero.I don't see anything specifically disallowing a zero sized iCCP chunk in the PNG spec, however the behaviour of LodePNG would have been inconsistent depending on whether or not the allocator returned NULL for a zero sized allocation or not.