OSDN Git Service

Fix buffer overflow when the last chunk is 4kb
authorVictor Hsieh <victorhsieh@google.com>
Fri, 19 Jan 2018 20:46:23 +0000 (12:46 -0800)
committerVictor Hsieh <victorhsieh@google.com>
Fri, 19 Jan 2018 20:47:09 +0000 (12:47 -0800)
Test: adb install GtsNetStatsTestCases.apk  # works only w/ the patch
Bug: 72189232
Bug: 30972906
Change-Id: I9f01279d783dd5adf31cfda4abd452240ad25ca3

core/java/android/util/apk/ApkVerityBuilder.java

index 7412ef4..a0d5e4c 100644 (file)
@@ -164,11 +164,11 @@ abstract class ApkVerityBuilder {
         }
 
         private void fillUpLastOutputChunk() {
-            int extra = (int) (BUFFER_SIZE - mOutput.position() % BUFFER_SIZE);
-            if (extra == 0) {
+            int lastBlockSize = (int) (mOutput.position() % BUFFER_SIZE);
+            if (lastBlockSize == 0) {
                 return;
             }
-            mOutput.put(ByteBuffer.allocate(extra));
+            mOutput.put(ByteBuffer.allocate(BUFFER_SIZE - lastBlockSize));
         }
     }