OSDN Git Service

Fix possible integer overflow in MtpStorage
authorHenrik Engström <henrik.engstrom@sonymobile.com>
Thu, 29 Nov 2012 14:29:35 +0000 (15:29 +0100)
committerHenrik Baard <henrik.baard@sonymobile.com>
Wed, 9 Jan 2013 08:27:59 +0000 (09:27 +0100)
When converting the MB value MtpReserveSpace value to bytes there is a
possible integer overflow since 3 integer values are multiplied, even
though the result is stored in a long variable. This would be visible when
the value is more than 2 GB. This is solved by making the constants
longs instead of ints.

Change-Id: I799129f7076a6e331cece17b5c05aed210499648

media/java/android/mtp/MtpStorage.java

index 9cf65a3..e20eabc 100644 (file)
@@ -39,7 +39,7 @@ public class MtpStorage {
         mStorageId = volume.getStorageId();
         mPath = volume.getPath();
         mDescription = context.getResources().getString(volume.getDescriptionId());
-        mReserveSpace = volume.getMtpReserveSpace() * 1024 * 1024;
+        mReserveSpace = volume.getMtpReserveSpace() * 1024L * 1024L;
         mRemovable = volume.isRemovable();
         mMaxFileSize = volume.getMaxFileSize();
     }