From 58d13ba9e371f5132197c1bd5874fc4a5129d085 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Wed, 28 Aug 2019 19:46:47 +0200 Subject: [PATCH] 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. --- .../main/java/com/beemdevelopment/aegis/otp/TotpInfo.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/otp/TotpInfo.java b/app/src/main/java/com/beemdevelopment/aegis/otp/TotpInfo.java index 27200592..1c91c54d 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/otp/TotpInfo.java +++ b/app/src/main/java/com/beemdevelopment/aegis/otp/TotpInfo.java @@ -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 {