OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkErrorInternals.h" | 10 #include "SkErrorInternals.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 | 131 |
132 void SkOrderedReadBuffer::readRegion(SkRegion* region) { | 132 void SkOrderedReadBuffer::readRegion(SkRegion* region) { |
133 fReader.readRegion(region); | 133 fReader.readRegion(region); |
134 } | 134 } |
135 | 135 |
136 void SkOrderedReadBuffer::readPath(SkPath* path) { | 136 void SkOrderedReadBuffer::readPath(SkPath* path) { |
137 fReader.readPath(path); | 137 fReader.readPath(path); |
138 } | 138 } |
139 | 139 |
140 uint32_t SkOrderedReadBuffer::readByteArray(void* value) { | 140 size_t SkOrderedReadBuffer::readByteArray(void* value, size_t size) { |
141 const uint32_t length = fReader.readU32(); | 141 size_t length = fReader.readU32(); |
| 142 if (length > size) { |
| 143 length = size; |
| 144 } |
142 memcpy(value, fReader.skip(SkAlign4(length)), length); | 145 memcpy(value, fReader.skip(SkAlign4(length)), length); |
143 return length; | 146 return length; |
144 } | 147 } |
145 | 148 |
146 uint32_t SkOrderedReadBuffer::readColorArray(SkColor* colors) { | 149 size_t SkOrderedReadBuffer::readColorArray(SkColor* colors, size_t size) { |
147 const uint32_t count = fReader.readU32(); | 150 const uint32_t count = fReader.readU32(); |
148 const uint32_t byteLength = count * sizeof(SkColor); | 151 size_t byteLength = count * sizeof(SkColor); |
| 152 if (byteLength > size) { |
| 153 byteLength = size; |
| 154 } |
149 memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength); | 155 memcpy(colors, fReader.skip(SkAlign4(byteLength)), byteLength); |
150 return count; | 156 return count; |
151 } | 157 } |
152 | 158 |
153 uint32_t SkOrderedReadBuffer::readIntArray(int32_t* values) { | 159 size_t SkOrderedReadBuffer::readIntArray(int32_t* values, size_t size) { |
154 const uint32_t count = fReader.readU32(); | 160 const uint32_t count = fReader.readU32(); |
155 const uint32_t byteLength = count * sizeof(int32_t); | 161 size_t byteLength = count * sizeof(int32_t); |
| 162 if (byteLength > size) { |
| 163 byteLength = size; |
| 164 } |
156 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); | 165 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); |
157 return count; | 166 return count; |
158 } | 167 } |
159 | 168 |
160 uint32_t SkOrderedReadBuffer::readPointArray(SkPoint* points) { | 169 size_t SkOrderedReadBuffer::readPointArray(SkPoint* points, size_t size) { |
161 const uint32_t count = fReader.readU32(); | 170 const uint32_t count = fReader.readU32(); |
162 const uint32_t byteLength = count * sizeof(SkPoint); | 171 size_t byteLength = count * sizeof(SkPoint); |
| 172 if (byteLength > size) { |
| 173 byteLength = size; |
| 174 } |
163 memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength); | 175 memcpy(points, fReader.skip(SkAlign4(byteLength)), byteLength); |
164 return count; | 176 return count; |
165 } | 177 } |
166 | 178 |
167 uint32_t SkOrderedReadBuffer::readScalarArray(SkScalar* values) { | 179 size_t SkOrderedReadBuffer::readScalarArray(SkScalar* values, size_t size) { |
168 const uint32_t count = fReader.readU32(); | 180 const uint32_t count = fReader.readU32(); |
169 const uint32_t byteLength = count * sizeof(SkScalar); | 181 size_t byteLength = count * sizeof(SkScalar); |
| 182 if (byteLength > size) { |
| 183 byteLength = size; |
| 184 } |
170 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); | 185 memcpy(values, fReader.skip(SkAlign4(byteLength)), byteLength); |
171 return count; | 186 return count; |
172 } | 187 } |
173 | 188 |
174 uint32_t SkOrderedReadBuffer::getArrayCount() { | 189 uint32_t SkOrderedReadBuffer::getArrayCount() { |
175 return *(uint32_t*)fReader.peek(); | 190 return *(uint32_t*)fReader.peek(); |
176 } | 191 } |
177 | 192 |
178 void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { | 193 void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { |
179 const int width = this->readInt(); | 194 const int width = this->readInt(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (sizeRecorded != sizeRead) { | 324 if (sizeRecorded != sizeRead) { |
310 // we could try to fix up the offset... | 325 // we could try to fix up the offset... |
311 sk_throw(); | 326 sk_throw(); |
312 } | 327 } |
313 } else { | 328 } else { |
314 // we must skip the remaining data | 329 // we must skip the remaining data |
315 fReader.skip(sizeRecorded); | 330 fReader.skip(sizeRecorded); |
316 } | 331 } |
317 return obj; | 332 return obj; |
318 } | 333 } |
OLD | NEW |