Skip to content
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

NULL being returned for a Boolean object #4232

Open
scuniff opened this issue Sep 8, 2024 · 0 comments
Open

NULL being returned for a Boolean object #4232

scuniff opened this issue Sep 8, 2024 · 0 comments

Comments

@scuniff
Copy link

scuniff commented Sep 8, 2024

public Boolean checkHeader() throws IOException {
if (in.length() < 4) return null;
// byte order must be II or MM
in.seek(0);
int endianOne = in.read();
int endianTwo = in.read();
boolean littleEndian = endianOne == TiffConstants.LITTLE &&
endianTwo == TiffConstants.LITTLE; // II
boolean bigEndian = endianOne == TiffConstants.BIG &&
endianTwo == TiffConstants.BIG; // MM
if (!littleEndian && !bigEndian) return null;
// check magic number (42)
in.order(littleEndian);
short magic = in.readShort();
bigTiff = magic == TiffConstants.BIG_TIFF_MAGIC_NUMBER;
if (magic != TiffConstants.MAGIC_NUMBER &&
magic != TiffConstants.BIG_TIFF_MAGIC_NUMBER)
{
return null;
}

Referring to above, there are 3 places in method checkHeader() a null is returned. This will cause a Null Pointer Exception for those callers that are returned the result to a boolean data type and not the Boolean object.

Here are 2 examples of callers expecting boolean data type and not Boolean object:

in.order(tp.checkHeader().booleanValue());

Here’s an example of code checking for NULL and taking appropriate action:

Boolean littleEndian = tiffParser.checkHeader();
if (littleEndian == null) {
throw new FormatException("Invalid TIFF file: " + id);
}
boolean little = littleEndian.booleanValue();

If it’s thought that this is an issue, my Eclipse seems to indicate there are about 10 other callers with this NPE situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant