File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -255,7 +255,28 @@ status_t BnCrypto::onTransact(
255
255
}
256
256
257
257
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 (
259
280
secure,
260
281
key,
261
282
iv,
@@ -264,6 +285,7 @@ status_t BnCrypto::onTransact(
264
285
subSamples, numSubSamples,
265
286
secure ? secureBufferId : dstPtr,
266
287
&errorDetailMsg);
288
+ }
267
289
268
290
reply->writeInt32 (result);
269
291
You can’t perform that action at this time.
0 commit comments