From: gogil Date: Sun, 14 Aug 2016 09:12:40 +0000 (-0700) Subject: Prevent overflows when using gamma_alloc_size X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~116^2~235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40ff5fe59b77b0b3e34467cc2f8666e4e88356f9;p=platform%2Fupstream%2FlibSkiaSharp.git Prevent overflows when using gamma_alloc_size BUG=636268 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2230163002 Review-Url: https://codereview.chromium.org/2230163002 --- diff --git a/AUTHORS b/AUTHORS index 35cf14c..a5e8965 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,6 +16,7 @@ Anthony Catel ARM <*@arm.com> Ehsan Akhgari George Wright +GiWan Go Google Inc. <*@google.com> Herb Derby Igalia <*@igalia.com> diff --git a/src/core/SkColorSpace_ICC.cpp b/src/core/SkColorSpace_ICC.cpp old mode 100644 new mode 100755 index f8ad47a..e28a746 --- a/src/core/SkColorSpace_ICC.cpp +++ b/src/core/SkColorSpace_ICC.cpp @@ -787,7 +787,9 @@ static bool load_a2b0(sk_sp* colorLUT, SkColorSpace::GammaNa if (SkGammas::Type::kNamed_Type == rType) { *gammaNamed = rData.fNamed; } else { - size_t allocSize = sizeof(SkGammas) + gamma_alloc_size(rType, rData); + size_t allocSize = sizeof(SkGammas); + return_if_false(safe_add(allocSize, gamma_alloc_size(rType, rData), &allocSize), + "SkGammas struct is too large to allocate"); void* memory = sk_malloc_throw(allocSize); *gammas = sk_sp(new (memory) SkGammas()); load_gammas(memory, 0, rType, &rData, rParams, rTagPtr); @@ -819,9 +821,13 @@ static bool load_a2b0(sk_sp* colorLUT, SkColorSpace::GammaNa tagLen); handle_invalid_gamma(&bType, &bData); - size_t allocSize = sizeof(SkGammas) + gamma_alloc_size(rType, rData) - + gamma_alloc_size(gType, gData) - + gamma_alloc_size(bType, bData); + size_t allocSize = sizeof(SkGammas); + return_if_false(safe_add(allocSize, gamma_alloc_size(rType, rData), &allocSize), + "SkGammas struct is too large to allocate"); + return_if_false(safe_add(allocSize, gamma_alloc_size(gType, gData), &allocSize), + "SkGammas struct is too large to allocate"); + return_if_false(safe_add(allocSize, gamma_alloc_size(bType, bData), &allocSize), + "SkGammas struct is too large to allocate"); void* memory = sk_malloc_throw(allocSize); *gammas = sk_sp(new (memory) SkGammas()); @@ -970,7 +976,10 @@ sk_sp SkColorSpace::NewICC(const void* input, size_t len) { if (SkGammas::Type::kNamed_Type == type) { gammaNamed = data.fNamed; } else { - size_t allocSize = sizeof(SkGammas) + gamma_alloc_size(type, data); + size_t allocSize = sizeof(SkGammas); + if (!safe_add(allocSize, gamma_alloc_size(type, data), &allocSize)) { + return_null("SkGammas struct is too large to allocate"); + } void* memory = sk_malloc_throw(allocSize); gammas = sk_sp(new (memory) SkGammas()); load_gammas(memory, 0, type, &data, params, r->addr(base)); @@ -1002,9 +1011,13 @@ sk_sp SkColorSpace::NewICC(const void* input, size_t len) { parse_gamma(&bData, &bParams, &tagBytes, b->addr(base), b->fLength); handle_invalid_gamma(&bType, &bData); - size_t allocSize = sizeof(SkGammas) + gamma_alloc_size(rType, rData) - + gamma_alloc_size(gType, gData) - + gamma_alloc_size(bType, bData); + size_t allocSize = sizeof(SkGammas); + if (!safe_add(allocSize, gamma_alloc_size(rType, rData), &allocSize) || + !safe_add(allocSize, gamma_alloc_size(gType, gData), &allocSize) || + !safe_add(allocSize, gamma_alloc_size(bType, bData), &allocSize)) + { + return_null("SkGammas struct is too large to allocate"); + } void* memory = sk_malloc_throw(allocSize); gammas = sk_sp(new (memory) SkGammas());