Loading libutils/FileMap.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -189,7 +189,11 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le int adjust = offset % mPageSize; off64_t adjOffset = offset - adjust; size_t adjLength = length + adjust; size_t adjLength; if (__builtin_add_overflow(length, adjust, &adjLength)) { ALOGE("adjusted length overflow: length %zu adjust %d", length, adjust); return false; } int flags = MAP_SHARED; int prot = PROT_READ; Loading libutils/FileMap_test.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -32,3 +32,16 @@ TEST(FileMap, zero_length_mapping) { ASSERT_EQ(0u, m.getDataLength()); ASSERT_EQ(4096, m.getDataOffset()); } TEST(FileMap, offset_overflow) { // Make sure that an end that overflows SIZE_MAX will not abort. // See http://b/156997193. TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); off64_t offset = 200; size_t length = SIZE_MAX; android::FileMap m; ASSERT_FALSE(m.create("test", tf.fd, offset, length, true)); } Loading
libutils/FileMap.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -189,7 +189,11 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le int adjust = offset % mPageSize; off64_t adjOffset = offset - adjust; size_t adjLength = length + adjust; size_t adjLength; if (__builtin_add_overflow(length, adjust, &adjLength)) { ALOGE("adjusted length overflow: length %zu adjust %d", length, adjust); return false; } int flags = MAP_SHARED; int prot = PROT_READ; Loading
libutils/FileMap_test.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -32,3 +32,16 @@ TEST(FileMap, zero_length_mapping) { ASSERT_EQ(0u, m.getDataLength()); ASSERT_EQ(4096, m.getDataOffset()); } TEST(FileMap, offset_overflow) { // Make sure that an end that overflows SIZE_MAX will not abort. // See http://b/156997193. TemporaryFile tf; ASSERT_TRUE(tf.fd != -1); off64_t offset = 200; size_t length = SIZE_MAX; android::FileMap m; ASSERT_FALSE(m.create("test", tf.fd, offset, length, true)); }