Skip to content

Commit 64ca46c

Browse files
jefftinkerandi34
authored andcommitted
Fix for security vulnerability in media server DO NOT MERGE
bug: 23540426 Change-Id: I5d602f99fd82e50d0136d47ce20cfa1ac9fd7ae2 (cherry picked from commit 9adc728)
1 parent 741632c commit 64ca46c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

media/libmedia/ICrypto.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,28 @@ status_t BnCrypto::onTransact(
255255
}
256256

257257
AString errorDetailMsg;
258-
ssize_t result = decrypt(
258+
ssize_t result;
259+
260+
size_t sumSubsampleSizes = 0;
261+
bool overflow = false;
262+
for (int32_t i = 0; i < numSubSamples; ++i) {
263+
CryptoPlugin::SubSample &ss = subSamples[i];
264+
if (sumSubsampleSizes <= SIZE_MAX - ss.mNumBytesOfEncryptedData) {
265+
sumSubsampleSizes += ss.mNumBytesOfEncryptedData;
266+
} else {
267+
overflow = true;
268+
}
269+
if (sumSubsampleSizes <= SIZE_MAX - ss.mNumBytesOfClearData) {
270+
sumSubsampleSizes += ss.mNumBytesOfClearData;
271+
} else {
272+
overflow = true;
273+
}
274+
}
275+
276+
if (overflow || sumSubsampleSizes != totalSize) {
277+
result = -EINVAL;
278+
} else {
279+
result = decrypt(
259280
secure,
260281
key,
261282
iv,
@@ -264,6 +285,7 @@ status_t BnCrypto::onTransact(
264285
subSamples, numSubSamples,
265286
secure ? secureBufferId : dstPtr,
266287
&errorDetailMsg);
288+
}
267289

268290
reply->writeInt32(result);
269291

0 commit comments

Comments
 (0)