diff options
author | Michael Lentine <mlentine@google.com> | 2014-10-31 15:25:03 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-01-28 10:38:06 -0800 |
commit | e0d7c636ec501366d2b360a7765cb378faa5ef87 (patch) | |
tree | 69eeb36847c4d20ea37a6d1dd13cf017f0f18359 | |
parent | 3250a13daea551e1130a5fda5d9d1a6d89fc8268 (diff) | |
download | android_frameworks_native-e0d7c636ec501366d2b360a7765cb378faa5ef87.tar.gz android_frameworks_native-e0d7c636ec501366d2b360a7765cb378faa5ef87.tar.bz2 android_frameworks_native-e0d7c636ec501366d2b360a7765cb378faa5ef87.zip |
Fix for corruption when numFds or numInts is too large.
Bug: 18076253
Change-Id: I4c5935440013fc755e1d123049290383f4659fb6
(cherry picked from commit dfd06b89a4b77fc75eb85a3c1c700da3621c0118)
-rw-r--r-- | libs/ui/GraphicBuffer.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index 86a464f0d..48b85d1c7 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -343,10 +343,19 @@ status_t GraphicBuffer::unflatten( const size_t numFds = buf[8]; const size_t numInts = buf[9]; + const size_t maxNumber = UINT_MAX / sizeof(int); + if (numFds >= maxNumber || numInts >= (maxNumber - 10)) { + width = height = stride = format = usage = 0; + handle = NULL; + ALOGE("unflatten: numFds or numInts is too large: %d, %d", + numFds, numInts); + return BAD_VALUE; + } + const size_t sizeNeeded = (10 + numInts) * sizeof(int); if (size < sizeNeeded) return NO_MEMORY; - size_t fdCountNeeded = 0; + size_t fdCountNeeded = numFds; if (count < fdCountNeeded) return NO_MEMORY; if (handle) { @@ -361,6 +370,12 @@ status_t GraphicBuffer::unflatten( format = buf[4]; usage = buf[5]; native_handle* h = native_handle_create(numFds, numInts); + if (!h) { + width = height = stride = format = usage = 0; + handle = NULL; + ALOGE("unflatten: native_handle_create failed"); + return NO_MEMORY; + } memcpy(h->data, fds, numFds*sizeof(int)); memcpy(h->data + numFds, &buf[10], numInts*sizeof(int)); handle = h; |