Fix NullPointerException issues in HeifReader and PngMetadataReader#708
Open
AndreCatarino wants to merge 1 commit intodrewnoakes:mainfrom
Open
Fix NullPointerException issues in HeifReader and PngMetadataReader#708AndreCatarino wants to merge 1 commit intodrewnoakes:mainfrom
AndreCatarino wants to merge 1 commit intodrewnoakes:mainfrom
Conversation
- Add null checks in HeifReader.extract() and PngMetadataReader.readMetadata() - Handle InputStream.available() edge case in HeifReader - Add @NotNull annotations for API clarity - Add unit tests for null parameter handling
drewnoakes
reviewed
Oct 5, 2025
Comment on lines
+60
to
+63
| int available = inputStream.available(); | ||
| // Some InputStreams return -1 for available(), so use a reasonable default | ||
| int markReadAheadLimit = (available > 0) ? available + 1 : 8192; | ||
| inputStream.mark(markReadAheadLimit); |
Owner
There was a problem hiding this comment.
Is there some additional context on this change? In what case were you seeing this? I'd like to think through the consequences of this a bit more.
Comment on lines
+44
to
+49
| if (inputStream == null) { | ||
| throw new IllegalArgumentException("inputStream cannot be null"); | ||
| } | ||
| if (handler == null) { | ||
| throw new IllegalArgumentException("handler cannot be null"); | ||
| } |
Owner
There was a problem hiding this comment.
There are probably thousands of such places where we don't validate parameter values as non-null. I'm not sure what value this adds in practice.
Comment on lines
-41
to
+42
| public void extract(InputStream inputStream, HeifHandler<?> handler) | ||
| public void extract(@NotNull InputStream inputStream, @NotNull HeifHandler<?> handler) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes
java.lang.NullPointerExceptionin stream reader initialization chain, particularly affecting HEIF and PNG metadata reading workflows.Root Cause: Missing null parameter validation in key entry points allows null InputStreams to propagate through the system, causing NPEs during StreamReader construction or method chaining.
Solution
inputStreamandhandlerparametersInputStream.available()edge case handling@NotNullannotations for better IDE supportChanges Made
HeifReader.extract()
inputStream != nullandhandler != nullIllegalArgumentExceptionwith descriptive messagesInputStream.available()handling when it returns -1PngMetadataReader.readMetadata()
Testing
HeifReaderTestwith 3 comprehensive test scenarios:Impact
@NotNullannotations help developers use the API correctly