Check for the possibility of an overflow when parsing OTP period

The conversion of the OTP period value to milliseconds may overflow for large
values, causing the result to wrap around to Integer.MIN_VALUE. This
subsequently caused a crash when calling ObjectAnimator.setDuration.
This commit is contained in:
Alexander Bakker 2019-08-28 19:46:47 +02:00
parent 9cb9d47857
commit 58d13ba9e3

View file

@ -55,7 +55,12 @@ public class TotpInfo extends OtpInfo {
}
public static boolean isPeriodValid(int period) {
return period > 0;
if (period <= 0) {
return false;
}
// check for the possibility of an overflow when converting to milliseconds
return period <= Integer.MAX_VALUE / 1000;
}
public void setPeriod(int period) throws OtpInfoException {