Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: src/core/SkMallocPixelRef.cpp

Issue 871993003: check for too-large rowBytes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use cast to keep minRB signed (matching the rest of the code) Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/BitmapTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMallocPixelRef.h" 8 #include "SkMallocPixelRef.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 51
52 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, 52 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
53 size_t requestedRowBytes, 53 size_t requestedRowBytes,
54 SkColorTable* ctable) { 54 SkColorTable* ctable) {
55 if (!is_valid(info, ctable)) { 55 if (!is_valid(info, ctable)) {
56 return NULL; 56 return NULL;
57 } 57 }
58 58
59 int32_t minRB = SkToS32(info.minRowBytes()); 59 // only want to permit 31bits of rowBytes
60 if (minRB < 0) { 60 int64_t minRB = (int64_t)info.minRowBytes64();
61 if (minRB < 0 || !sk_64_isS32(minRB)) {
61 return NULL; // allocation will be too large 62 return NULL; // allocation will be too large
62 } 63 }
63 if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) { 64 if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) {
64 return NULL; // cannot meet requested rowbytes 65 return NULL; // cannot meet requested rowbytes
65 } 66 }
66 67
67 int32_t rowBytes; 68 int32_t rowBytes;
68 if (requestedRowBytes) { 69 if (requestedRowBytes) {
69 rowBytes = SkToS32(requestedRowBytes); 70 rowBytes = SkToS32(requestedRowBytes);
70 } else { 71 } else {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { 199 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const {
199 return this->info().getSafeSize(fRB); 200 return this->info().getSafeSize(fRB);
200 } 201 }
201 202
202 /////////////////////////////////////////////////////////////////////////////// 203 ///////////////////////////////////////////////////////////////////////////////
203 204
204 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t rowBytes, 205 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t rowBytes,
205 SkColorTable* ctable) { 206 SkColorTable* ctable) {
206 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable); 207 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable);
207 } 208 }
OLDNEW
« no previous file with comments | « no previous file | tests/BitmapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698