OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkValidatingReadBuffer.h" | 10 #include "SkValidatingReadBuffer.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 142 } |
143 | 143 |
144 void SkValidatingReadBuffer::readPath(SkPath* path) { | 144 void SkValidatingReadBuffer::readPath(SkPath* path) { |
145 const size_t size = path->readFromMemory(fReader.peek()); | 145 const size_t size = path->readFromMemory(fReader.peek()); |
146 fError = fError || (SkAlign4(size) != size); | 146 fError = fError || (SkAlign4(size) != size); |
147 if (!fError) { | 147 if (!fError) { |
148 (void)this->skip(size); | 148 (void)this->skip(size); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 uint32_t SkValidatingReadBuffer::readByteArray(void* value) { | 152 size_t SkValidatingReadBuffer::readByteArray(void* value, size_t size) { |
153 const uint32_t length = this->readUInt(); | 153 const uint32_t length = this->readUInt(); |
| 154 fError = fError || (size != length); |
154 const void* ptr = this->skip(SkAlign4(length)); | 155 const void* ptr = this->skip(SkAlign4(length)); |
155 if (!fError) { | 156 if (!fError) { |
156 memcpy(value, ptr, length); | 157 memcpy(value, ptr, length); |
157 return length; | 158 return length; |
158 } | 159 } |
159 return 0; | 160 return 0; |
160 } | 161 } |
161 | 162 |
162 uint32_t SkValidatingReadBuffer::readColorArray(SkColor* colors) { | 163 size_t SkValidatingReadBuffer::readColorArray(SkColor* colors, size_t size) { |
163 const uint32_t count = this->readUInt(); | 164 const uint32_t count = this->readUInt(); |
164 const uint32_t byteLength = count * sizeof(SkColor); | 165 const size_t byteLength = count * sizeof(SkColor); |
| 166 fError = fError || (size != byteLength); |
165 const void* ptr = this->skip(SkAlign4(byteLength)); | 167 const void* ptr = this->skip(SkAlign4(byteLength)); |
166 if (!fError) { | 168 if (!fError) { |
167 memcpy(colors, ptr, byteLength); | 169 memcpy(colors, ptr, byteLength); |
168 return count; | 170 return count; |
169 } | 171 } |
170 return 0; | 172 return 0; |
171 } | 173 } |
172 | 174 |
173 uint32_t SkValidatingReadBuffer::readIntArray(int32_t* values) { | 175 size_t SkValidatingReadBuffer::readIntArray(int32_t* values, size_t size) { |
174 const uint32_t count = this->readUInt(); | 176 const uint32_t count = this->readUInt(); |
175 const uint32_t byteLength = count * sizeof(int32_t); | 177 const size_t byteLength = count * sizeof(int32_t); |
| 178 fError = fError || (size != byteLength); |
176 const void* ptr = this->skip(SkAlign4(byteLength)); | 179 const void* ptr = this->skip(SkAlign4(byteLength)); |
177 if (!fError) { | 180 if (!fError) { |
178 memcpy(values, ptr, byteLength); | 181 memcpy(values, ptr, byteLength); |
179 return count; | 182 return count; |
180 } | 183 } |
181 return 0; | 184 return 0; |
182 } | 185 } |
183 | 186 |
184 uint32_t SkValidatingReadBuffer::readPointArray(SkPoint* points) { | 187 size_t SkValidatingReadBuffer::readPointArray(SkPoint* points, size_t size) { |
185 const uint32_t count = this->readUInt(); | 188 const uint32_t count = this->readUInt(); |
186 const uint32_t byteLength = count * sizeof(SkPoint); | 189 const size_t byteLength = count * sizeof(SkPoint); |
| 190 fError = fError || (size != byteLength); |
187 const void* ptr = this->skip(SkAlign4(byteLength)); | 191 const void* ptr = this->skip(SkAlign4(byteLength)); |
188 if (!fError) { | 192 if (!fError) { |
189 memcpy(points, ptr, byteLength); | 193 memcpy(points, ptr, byteLength); |
190 return count; | 194 return count; |
191 } | 195 } |
192 return 0; | 196 return 0; |
193 } | 197 } |
194 | 198 |
195 uint32_t SkValidatingReadBuffer::readScalarArray(SkScalar* values) { | 199 size_t SkValidatingReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
196 const uint32_t count = this->readUInt(); | 200 const uint32_t count = this->readUInt(); |
197 const uint32_t byteLength = count * sizeof(SkScalar); | 201 const size_t byteLength = count * sizeof(SkScalar); |
| 202 fError = fError || (size != byteLength); |
198 const void* ptr = this->skip(SkAlign4(byteLength)); | 203 const void* ptr = this->skip(SkAlign4(byteLength)); |
199 if (!fError) { | 204 if (!fError) { |
200 memcpy(values, ptr, byteLength); | 205 memcpy(values, ptr, byteLength); |
201 return count; | 206 return count; |
202 } | 207 } |
203 return 0; | 208 return 0; |
204 } | 209 } |
205 | 210 |
206 uint32_t SkValidatingReadBuffer::getArrayCount() { | 211 uint32_t SkValidatingReadBuffer::getArrayCount() { |
207 return *(uint32_t*)fReader.peek(); | 212 return *(uint32_t*)fReader.peek(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 delete obj; | 259 delete obj; |
255 obj = NULL; | 260 obj = NULL; |
256 } | 261 } |
257 } else { | 262 } else { |
258 // we must skip the remaining data | 263 // we must skip the remaining data |
259 this->skip(sizeRecorded); | 264 this->skip(sizeRecorded); |
260 SkASSERT(false); | 265 SkASSERT(false); |
261 } | 266 } |
262 return obj; | 267 return obj; |
263 } | 268 } |
OLD | NEW |