am 3d89edca: am e6f7a44e: Fix for corruption when numFds or numInts is too large.

* commit '3d89edca65e07319c9ac3b9bb9889e80e8c40578':
  Fix for corruption when numFds or numInts is too large.
This commit is contained in:
Michael Lentine 2014-12-02 17:52:00 +00:00 committed by Android Git Automerger
commit 76ebd319d9
1 changed files with 16 additions and 1 deletions

View File

@ -251,10 +251,19 @@ status_t GraphicBuffer::unflatten(
const size_t numFds = buf[6];
const size_t numInts = buf[7];
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 = (8 + 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) {
@ -269,6 +278,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[8], numInts*sizeof(int));
handle = h;