Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b62a64e0 authored by Victor Hsieh's avatar Victor Hsieh
Browse files

Fix buffer overflow when the last chunk is 4kb

Test: adb install GtsNetStatsTestCases.apk  # works only w/ the patch
Bug: 72189232
Bug: 30972906
Change-Id: I9f01279d783dd5adf31cfda4abd452240ad25ca3
parent 98602c5b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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));
        }
    }