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

Commit 62e83c95 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Check for crypto size overflow

Bug: 111922341
Test: build
Change-Id: Icfe2d15c13f1b4bb77e0a9684ffc1284f557e6d5
parent 19283e9d
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -239,8 +239,14 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::makeCryptoInfo(
        size_t *encryptedbytes)
{
    // size needed to store all the crypto data
    size_t cryptosize = sizeof(CryptoInfo) +
                        sizeof(CryptoPlugin::SubSample) * numSubSamples;
    size_t cryptosize;
    // sizeof(CryptoInfo) + sizeof(CryptoPlugin::SubSample) * numSubSamples;
    if (__builtin_mul_overflow(sizeof(CryptoPlugin::SubSample), numSubSamples, &cryptosize) ||
            __builtin_add_overflow(cryptosize, sizeof(CryptoInfo), &cryptosize)) {
        ALOGE("crypto size overflow");
        return NULL;
    }

    CryptoInfo *ret = (CryptoInfo*) malloc(cryptosize);
    if (ret == NULL) {
        ALOGE("couldn't allocate %zu bytes", cryptosize);