int endOfTags = mIfdStartOffset + OFFSET_SIZE + TAG_SIZE * mNumOfTagInIfd;
if (offset < endOfTags) {
mTag = readTag();
+ if (mTag == null) {
+ return next();
+ }
if (mNeedToParseOffsetsInCurrentIfd) {
checkOffsetOrImageTag(mTag);
}
if (mNeedToParseOffsetsInCurrentIfd) {
while (offset < endOfTags) {
mTag = readTag();
- checkOffsetOrImageTag(mTag);
offset += TAG_SIZE;
+ if (mTag == null) continue;
+ checkOffsetOrImageTag(mTag);
}
} else {
skipTo(endOfTags);
throw new ExifInvalidFormatException(
"Number of component is larger then Integer.MAX_VALUE");
}
+ // Some invalid image file contains invalid data type. Ignore those tags
+ if (!ExifTag.isValidType(dataFormat)) {
+ Log.w(TAG, String.format("Tag %04x: Invalid data type %d", tagId, dataFormat));
+ mTiffStream.skip(4);
+ return null;
+ }
ExifTag tag = new ExifTag(tagId, dataFormat, (int) numOfComp, mIfdType);
int dataSize = tag.getDataSize();
if (dataSize > 4) {
IfdId.TYPE_IFD_INTEROPERABILITY);
}
+ static boolean isValidType(short type) {
+ return type == TYPE_UNSIGNED_BYTE || type == TYPE_ASCII ||
+ type == TYPE_UNSIGNED_SHORT || type == TYPE_UNSIGNED_LONG ||
+ type == TYPE_UNSIGNED_RATIONAL || type == TYPE_UNDEFINED ||
+ type == TYPE_LONG || type == TYPE_RATIONAL;
+ }
+
ExifTag(short tagId, short type, int componentCount, int ifd) {
mTagId = tagId;
mDataType = type;