check for big sizes in NewData

BUG=486977

Review URL: https://codereview.chromium.org/1148873004
This commit is contained in:
reed 2015-05-20 13:06:00 -07:00 committed by Commit bot
parent 76be9c8dc0
commit e12fcd5fff

View File

@ -63,7 +63,14 @@ SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) {
if (0 == length) {
return SkData::NewEmpty();
}
char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length);
const size_t actualLength = length + sizeof(SkData);
if (actualLength < length) {
// we overflowed
sk_throw();
}
char* storage = (char*)sk_malloc_throw(actualLength);
SkData* data = new (storage) SkData(length);
if (srcOrNull) {
memcpy(data->writable_data(), srcOrNull, length);