-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fallback to original URL if the beginIndex is invalid #143
Conversation
return "https://i0.wp.com/" + imageUrl.substring(schemePos + 3, imageUrl.length()) + query; | ||
int beginIndex = schemePos + 3; | ||
if (beginIndex < 0 || beginIndex > imageUrl.length()) { | ||
// Fallback to original URL if the beginIndex is invalid to avoid `StringIndexOutOfBoundsException` |
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.
NP: It seems that imageUrl
is conditionally mutated a few times prior to this. Should we tweak this code comment to not mention "original" URL? Or, alternatively, if that is what we want, store it in a local var at the top of the function and return it here without mutation? 🤔
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.
WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java
Outdated
Show resolved
Hide resolved
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.
I left a couple of minor questions, but I consider them non-blocking, since I believe the implementation changes here are already an improvement over crashing out of bounds.
Thank you for reviewing and your feedback @mkevins 🙇 |
Fixes wordpress-mobile/WordPress-Android#18626
WordPress-Android PR: wordpress-mobile/WordPress-Android#20459
Description
Checks the begin index before calling the substring function to prevent the
StringIndexOutOfBoundsException
To test
I was not able to reproduce the issue but there are 5 different crashes rooting from this exception (see wordpress-mobile/WordPress-Android#18626 (comment))
I managed to fake one URL that reproduces the crash and added a test for it.