[automerger skipped] Merge "Merge ab/7061308 into stage." into stage-aosp-master am: 533fbfb117 -s ours

am skip reason: Change-Id I1512f0aee1f960e809a42448b9aafed0de3dbc2a with SHA-1 2be17732e7 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/interfaces/+/13658370

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ic4930126e19d855ba6cd216cce41f49832a65302
diff --git a/drm/1.0/default/CryptoPlugin.cpp b/drm/1.0/default/CryptoPlugin.cpp
index 2db3607..e6d4e84 100644
--- a/drm/1.0/default/CryptoPlugin.cpp
+++ b/drm/1.0/default/CryptoPlugin.cpp
@@ -124,7 +124,11 @@
             return Void();
         }
 
-        if (source.offset + offset + source.size > sourceBase->getSize()) {
+        size_t totalSize = 0;
+        if (__builtin_add_overflow(source.offset, offset, &totalSize) ||
+            __builtin_add_overflow(totalSize, source.size, &totalSize) ||
+            totalSize > sourceBase->getSize()) {
+            android_errorWriteLog(0x534e4554, "176496160");
             _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
             return Void();
         }