Merge "Fail explicitly on length overflow." into oc-dev am: ea8d38e77f

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/11619803

Change-Id: I9a6def9ff590fdadb457e9a011df3532829d23f4
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index 3c4d81c..2e19d66 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -190,6 +190,10 @@
     adjust = offset % mPageSize;
     adjOffset = offset - adjust;
     adjLength = length + adjust;
+    if (__builtin_add_overflow(length, adjust, &adjLength)) {
+        ALOGE("adjusted length overflow: length %zu adjust %d", length, adjust);
+        return false;
+    }
 
     flags = MAP_SHARED;
     prot = PROT_READ;