-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fixes null pointer exception in PNG extension module (issue #148) #580
Conversation
Fix for issue openpreserve#148. The `_module.addKeyword` call was inside the loop that processed 1 byte at a time. As a result values were not populated properly and this created and NPE. Also resolved a few other logic issues within `ItxtChunk.processChunk()`.
This uses the image in issue openpreserve#148 to do a test for iTXt chunk processing.
Codecov Report
@@ Coverage Diff @@
## integration #580 +/- ##
==============================================
Coverage 45.63% 45.63%
Complexity 1046 1046
==============================================
Files 57 57
Lines 9149 9149
Branches 1687 1687
==============================================
Hits 4175 4175
Misses 4424 4424
Partials 550 550 Continue to review full report at Codecov.
|
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.
The only issue remaining is that of nulls vs. zeros and I'll discuss in the conversation.
/** | ||
* Representation of the iTXt (internationalized text) chunk | ||
* | ||
* @see <a href="https://www.w3.org/TR/PNG/#11iTXt">https://www.w3.org/TR/PNG/#11iTXt</a> |
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.
Nice :)
The null catch is good detective work. I've had a good scan of https://www.w3.org/TR/PNG/ paying attention to what it says about nulls. What I've learned is:
The key text for the compression values reads:
So the only field that matters is the flag as the type should read 0 regardless, it's only a "future proof" marker and is currently redundant. So this leaves the flag with is set 0 for uncompressed text and 1 for compressed text. This situation is fairly typical specification stuff, and it's hard to make everything explicit when writing these documents. I'd be reluctant to make these validation errors without having a feel as to how many files it will cause to fail. I'm not sure JHOVE users should be our method of establishing that 50% of files use null values and image viewers care not. We're waiting briefly to find out about the file (below) so can think some more. If we decide to detect and report I feel that we should introduce a warning and see how may, if any, of the test samples cause the warning.
I've asked @ross-spencer at #148 if this would be OK. I'll keep the PR on hold for now if that's OK? |
@carlwilson Your reasoning for not creating an error for the nulls in those positions makes perfect sense from my perspective. |
We have not yet received permission to include the test image, so I've looked at alternatives. I wasn't able to add the iTxt fields using a hex editor, so I found another source for an example. This site has a lot of good test files for PNG, and the license supports distribution and reuse: http://www.schaik.com/pngsuite/. I've confirmed I can replicate the error using their test file, and I'm working on updating the test to point to this example instead. I'll push an update shortly. This seems like a good source if more files are needed for the PNG test copora. |
Outstanding stuff @karenhanson and thanks for the test corpus tips, this will be merged shortly. |
This relates to issue #148. Some background:
com.macgath.jhove.module.png.ItxtChunk
.The NPE was happening for several reasons. First, this piece of code that adds keywords to the properties list was inside the loop that was processing the chunk one byte at a time, rather than outside of the loop where all bytes in the chunks had been processed. This meant most of the values were still null on the first loop when it was run, triggering the NPE.
There were also several logic issues within the loop where string bytes were not being fully processed before moving on to the next part of the chunk.
Notes for consideration before merging
0
, so the null shows up as0
. The documentation doesn't say that it's OK to put a null there, so I'm wondering if this is actually a minor error.