aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
Diffstat (limited to 'sdkmanager')
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java42
1 files changed, 30 insertions, 12 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java
index c4914b2..35ce0b0 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java
@@ -607,18 +607,36 @@ public final class AvdManager {
Matcher m = SDCARD_SIZE_PATTERN.matcher(sdcard);
if (m.matches()) {
// get the sdcard values for checks
- int sdcardSize = Integer.parseInt(m.group(1)); // pattern check
- // above makes
- // this unlikely to fail
- String sdcardSizeModifier = m.group(2);
- if ("K".equals(sdcardSizeModifier)) {
- sdcardSize *= 1024;
- } else { // must be "M" per the pattern
- sdcardSize *= 1024 * 1024;
- }
-
- if (sdcardSize < 9 * 1024 * 1024) {
- log.error(null, "SD Card size must be at least 9MB");
+ try {
+ long sdcardSize = Long.parseLong(m.group(1));
+
+ // prevent overflow: no more than 999GB
+ // 10 digit for MiB, 13 for KiB
+ int digitCount = m.group(1).length();
+
+ String sdcardSizeModifier = m.group(2);
+ if ("K".equals(sdcardSizeModifier)) {
+ sdcardSize *= 1024L;
+ } else { // must be "M" per the pattern
+ sdcardSize *= 1024L * 1024L;
+ digitCount += 3; // convert the number of digit into "KiB"
+ }
+
+ if (digitCount >= 13) {
+ log.error(null, "SD Card size is too big!");
+ needCleanup = true;
+ return null;
+ }
+
+ if (sdcardSize < 9 * 1024 * 1024) {
+ log.error(null, "SD Card size must be at least 9MB");
+ needCleanup = true;
+ return null;
+ }
+ } catch (NumberFormatException e) {
+ // this should never happen since the string is validated
+ // by the regexp
+ log.error(null, "Unable to parse SD Card size");
needCleanup = true;
return null;
}