@1.2::IServiceManager: client callback
am: 3c60ff1438

Change-Id: I1d0ea9171c99eafad03b26290b1d108db2bd1728
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index a2ca5fa..c9b2693 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -22,6 +22,7 @@
 #include <hwbinder/IPCThreadState.h>
 
 // C includes
+#include <inttypes.h>
 #include <unistd.h>
 
 // C++ includes
@@ -94,6 +95,15 @@
                 parentOffset + hidl_memory::kOffsetOfName);
     }
 
+    // hidl_memory's size is stored in uint64_t, but mapMemory's mmap will map
+    // size in size_t. If size is over SIZE_MAX, mapMemory could succeed
+    // but the mapped memory's actual size will be smaller than the reported size.
+    if (memory.size() > SIZE_MAX) {
+        ALOGE("Cannot use memory with %" PRId64 " bytes because it is too large.", memory.size());
+        android_errorWriteLog(0x534e4554, "79376389");
+        return BAD_VALUE;
+    }
+
     return _hidl_err;
 }