-
Notifications
You must be signed in to change notification settings - Fork 484
java.lang.StringIndexOutOfBoundsException processing a .JPG file #685
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
Comments
Forgot to mention.... I'm using metadata-extractor-2.19.0.jar. |
Thanks for the bug report and sample image. Will happily accept a pull request for this. |
Upon reviewing the attached image, I noticed that there are multiple Using HxD to analyze the file, I observed that the first I would like to ask for guidance on how to handle this kind of situation. Is there a proper way to interpret these split entries in ICC tags? Moreover, are there any recommendations for recovering corrupted data in such cases? Lastly, I kindly ask for your understanding as this message was translated from Korean to English, and there might be some unnatural phrasing. |
안녕하세요! 의견 주셔서 감사합니다. 저는 사실 한국어를 공부하고 있는 학생이에요. 아내가 한국 사람이라서 집에서 조금씩 한국어로 대화하고 있어요. It seems like the exception is coming from here: metadata-extractor/Source/com/drew/metadata/icc/IccDescriptor.java Lines 92 to 94 in 0c3452b
In this case we read I think we should add some validation, and throw a It may be that other tags after this are corrupted too, and that the library produces some junk data. |
Hello, @drewnoakes! First of all, it's great to hear that you are learning Korean. I reviewed the code and attempted to validate the case ICC_TAG_TYPE_DESC:
int stringLength = reader.getInt32(8);
if (stringLength < 1 || stringLength > (bytes.length - 12))
throw new BufferBoundsException(
String.format("Invalid stringLength in ICC profile. Found: %d, Expected: between 1 and %d.",
stringLength, bytes.length - 12)
);
return new String(bytes, 12, stringLength - 1); The data validation works correctly, but I realized the need to devise a better method instead of relying on the tag call. Additionally, I confirmed that other tags are functioning correctly. I will think about this further and share an improved solution once I have it. Thank you! |
Looks good! I think a zero length should be valid. Also the reception constructor has an overload that takes numbers and constructs the message for you. |
Hello @drewnoakes,
case ICC_TAG_TYPE_DESC:
int stringLength = reader.getInt32(8);
if (stringLength < 0 || stringLength > (bytes.length - 12)) {
throw new BufferBoundsException(12, stringLength, bytes.length);
}
return new String(bytes, 12, stringLength - 1); Please let me know if further review or improvements are needed. |
That looks great to me @DAN-MU-ZI. Would you like to submit the change as a pull request? |
…nt exceptions Resolved an issue where malformed ICC profiles could cause a StringIndexOutOfBoundsException during DESC tag processing. - Added validation to ensure `stringLength` is non-negative and does not exceed `bytes.length - 12`. - Throws `BufferBoundsException` with a detailed message for invalid cases. - Ensures corrupted ICC profiles are handled gracefully.
Issue #685 | Fix StringIndexOutOfBoundsException in ICC DESC tag processing
Getting StringIndexOutOfBoundsException on the included .JPG file. Here's the code:
The text was updated successfully, but these errors were encountered: