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

Side by Side Diff: third_party/WebKit/Source/core/html/ImageData.cpp

Issue 1814563002: wtf/CheckedArithmetic.h delegates to base/numerics/safe_math.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 21 matching lines...) Expand all
32 #include "bindings/core/v8/V8Uint8ClampedArray.h" 32 #include "bindings/core/v8/V8Uint8ClampedArray.h"
33 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
34 #include "core/frame/ImageBitmap.h" 34 #include "core/frame/ImageBitmap.h"
35 #include "core/imagebitmap/ImageBitmapOptions.h" 35 #include "core/imagebitmap/ImageBitmapOptions.h"
36 #include "platform/RuntimeEnabledFeatures.h" 36 #include "platform/RuntimeEnabledFeatures.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 ImageData* ImageData::create(const IntSize& size) 40 ImageData* ImageData::create(const IntSize& size)
41 { 41 {
42 Checked<int, RecordOverflow> dataSize = 4; 42 WTF::CheckedNumeric<int> dataSize = 4;
43 dataSize *= size.width(); 43 dataSize *= size.width();
44 dataSize *= size.height(); 44 dataSize *= size.height();
45 if (dataSize.hasOverflowed() || dataSize.unsafeGet() < 0) 45 if (!dataSize.IsValid() || dataSize.ValueOrDie() < 0)
46 return nullptr; 46 return nullptr;
47 47
48 RefPtr<DOMUint8ClampedArray> byteArray = 48 RefPtr<DOMUint8ClampedArray> byteArray = DOMUint8ClampedArray::createOrNull( dataSize.ValueOrDie());
49 DOMUint8ClampedArray::createOrNull(dataSize.unsafeGet());
50 if (!byteArray) 49 if (!byteArray)
51 return nullptr; 50 return nullptr;
52 51
53 return new ImageData(size, byteArray.release()); 52 return new ImageData(size, byteArray.release());
54 } 53 }
55 54
56 ImageData* ImageData::create(const IntSize& size, PassRefPtr<DOMUint8ClampedArra y> byteArray) 55 ImageData* ImageData::create(const IntSize& size, PassRefPtr<DOMUint8ClampedArra y> byteArray)
57 { 56 {
58 Checked<int, RecordOverflow> dataSize = 4; 57 WTF::CheckedNumeric<int> dataSize = 4;
59 dataSize *= size.width(); 58 dataSize *= size.width();
60 dataSize *= size.height(); 59 dataSize *= size.height();
61 if (dataSize.hasOverflowed()) 60 if (!dataSize.IsValid())
62 return nullptr; 61 return nullptr;
63 62
64 if (dataSize.unsafeGet() < 0 63 if (dataSize.ValueOrDie() < 0
65 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) 64 || static_cast<unsigned>(dataSize.ValueOrDie()) > byteArray->length())
66 return nullptr; 65 return nullptr;
67 66
68 return new ImageData(size, byteArray); 67 return new ImageData(size, byteArray);
69 } 68 }
70 69
71 ImageData* ImageData::create(unsigned width, unsigned height, ExceptionState& ex ceptionState) 70 ImageData* ImageData::create(unsigned width, unsigned height, ExceptionState& ex ceptionState)
72 { 71 {
73 if (!width || !height) { 72 if (!width || !height) {
74 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is zero or not a number.", width ? "height" : "width")); 73 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is zero or not a number.", width ? "height" : "width"));
75 return nullptr; 74 return nullptr;
76 } 75 }
77 76
78 Checked<unsigned, RecordOverflow> dataSize = 4; 77 WTF::CheckedNumeric<unsigned> dataSize = 4;
79 dataSize *= width; 78 dataSize *= width;
80 dataSize *= height; 79 dataSize *= height;
81 if (dataSize.hasOverflowed() 80 if (!dataSize.IsValid()
82 || static_cast<int>(width) < 0 81 || static_cast<int>(width) < 0
83 || static_cast<int>(height) < 0) { 82 || static_cast<int>(height) < 0) {
84 exceptionState.throwDOMException(IndexSizeError, "The requested image si ze exceeds the supported range."); 83 exceptionState.throwDOMException(IndexSizeError, "The requested image si ze exceeds the supported range.");
85 return nullptr; 84 return nullptr;
86 } 85 }
87 86
88 RefPtr<DOMUint8ClampedArray> byteArray = 87 RefPtr<DOMUint8ClampedArray> byteArray = DOMUint8ClampedArray::createOrNull( dataSize.ValueOrDie());
89 DOMUint8ClampedArray::createOrNull(dataSize.unsafeGet());
90 if (!byteArray) { 88 if (!byteArray) {
91 exceptionState.throwDOMException(V8GeneralError, "Out of memory at Image Data creation"); 89 exceptionState.throwDOMException(V8GeneralError, "Out of memory at Image Data creation");
92 return nullptr; 90 return nullptr;
93 } 91 }
94 92
95 return new ImageData(IntSize(width, height), byteArray.release()); 93 return new ImageData(IntSize(width, height), byteArray.release());
96 } 94 }
97 95
98 bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data, unsigne d width, unsigned& lengthInPixels, ExceptionState& exceptionState) 96 bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data, unsigne d width, unsigned& lengthInPixels, ExceptionState& exceptionState)
99 { 97 {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ASSERT(size.width() >= 0 && size.height() >= 0); 180 ASSERT(size.width() >= 0 && size.height() >= 0);
183 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h eight() * 4) <= m_data->length()); 181 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h eight() * 4) <= m_data->length());
184 } 182 }
185 183
186 void ImageData::dispose() 184 void ImageData::dispose()
187 { 185 {
188 m_data.clear(); 186 m_data.clear();
189 } 187 }
190 188
191 } // namespace blink 189 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698