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

Commit f1307ef2 authored by Robert Shih's avatar Robert Shih Committed by Android (Google) Code Review
Browse files

Merge "clearkey hidl: fix oob read in decrypt" into pi-dev

parents b6b78798 fa3781fe
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -117,14 +117,17 @@ Return<void> CryptoPlugin::decrypt(
    // Calculate the output buffer size and determine if any subsamples are
    // encrypted.
    size_t destSize = 0;
    size_t srcSize = 0;
    bool haveEncryptedSubsamples = false;
    for (size_t i = 0; i < subSamples.size(); i++) {
        const SubSample &subSample = subSamples[i];
        if (__builtin_add_overflow(destSize, subSample.numBytesOfClearData, &destSize)) {
        if (__builtin_add_overflow(destSize, subSample.numBytesOfClearData, &destSize) ||
            __builtin_add_overflow(srcSize, subSample.numBytesOfClearData, &srcSize)) {
            _hidl_cb(Status::BAD_VALUE, 0, "subsample clear size overflow");
            return Void();
        }
        if (__builtin_add_overflow(destSize, subSample.numBytesOfEncryptedData, &destSize)) {
        if (__builtin_add_overflow(destSize, subSample.numBytesOfEncryptedData, &destSize) ||
            __builtin_add_overflow(srcSize, subSample.numBytesOfEncryptedData, &srcSize)) {
            _hidl_cb(Status::BAD_VALUE, 0, "subsample encrypted size overflow");
            return Void();
        }
@@ -133,7 +136,7 @@ Return<void> CryptoPlugin::decrypt(
        }
    }

    if (destSize > destBuffer.size) {
    if (destSize > destBuffer.size || srcSize > source.size) {
        _hidl_cb(Status::BAD_VALUE, 0, "subsample sum too large");
        return Void();
    }