| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 return data; | 107 return data; |
| 108 } | 108 } |
| 109 | 109 |
| 110 void SkValidatingReadBuffer::readPoint(SkPoint* point) { | 110 void SkValidatingReadBuffer::readPoint(SkPoint* point) { |
| 111 point->fX = fReader.readScalar(); | 111 point->fX = fReader.readScalar(); |
| 112 point->fY = fReader.readScalar(); | 112 point->fY = fReader.readScalar(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { | 115 void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { |
| 116 const size_t size = matrix->readFromMemory(fReader.peek()); | 116 const size_t size = matrix->readFromMemory(fReader.peek(), fReader.available
()); |
| 117 fError = fError || (SkAlign4(size) != size); | 117 fError = fError || (SkAlign4(size) != size) || (0 == size); |
| 118 if (!fError) { | 118 if (!fError) { |
| 119 (void)this->skip(size); | 119 (void)this->skip(size); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void SkValidatingReadBuffer::readIRect(SkIRect* rect) { | 123 void SkValidatingReadBuffer::readIRect(SkIRect* rect) { |
| 124 const void* ptr = this->skip(sizeof(SkIRect)); | 124 const void* ptr = this->skip(sizeof(SkIRect)); |
| 125 if (!fError) { | 125 if (!fError) { |
| 126 memcpy(rect, ptr, sizeof(SkIRect)); | 126 memcpy(rect, ptr, sizeof(SkIRect)); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SkValidatingReadBuffer::readRect(SkRect* rect) { | 130 void SkValidatingReadBuffer::readRect(SkRect* rect) { |
| 131 const void* ptr = this->skip(sizeof(SkRect)); | 131 const void* ptr = this->skip(sizeof(SkRect)); |
| 132 if (!fError) { | 132 if (!fError) { |
| 133 memcpy(rect, ptr, sizeof(SkRect)); | 133 memcpy(rect, ptr, sizeof(SkRect)); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void SkValidatingReadBuffer::readRegion(SkRegion* region) { | 137 void SkValidatingReadBuffer::readRegion(SkRegion* region) { |
| 138 const size_t size = region->readFromMemory(fReader.peek()); | 138 const size_t size = region->readFromMemory(fReader.peek(), fReader.available
()); |
| 139 fError = fError || (SkAlign4(size) != size); | 139 fError = fError || (SkAlign4(size) != size) || (0 == size); |
| 140 if (!fError) { | 140 if (!fError) { |
| 141 (void)this->skip(size); | 141 (void)this->skip(size); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SkValidatingReadBuffer::readPath(SkPath* path) { | 145 void SkValidatingReadBuffer::readPath(SkPath* path) { |
| 146 const size_t size = path->readFromMemory(fReader.peek()); | 146 const size_t size = path->readFromMemory(fReader.peek(), fReader.available()
); |
| 147 fError = fError || (SkAlign4(size) != size); | 147 fError = fError || (SkAlign4(size) != size) || (0 == size); |
| 148 if (!fError) { | 148 if (!fError) { |
| 149 (void)this->skip(size); | 149 (void)this->skip(size); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 uint32_t SkValidatingReadBuffer::readByteArray(void* value) { | 153 uint32_t SkValidatingReadBuffer::readByteArray(void* value) { |
| 154 const uint32_t length = this->readUInt(); | 154 const uint32_t length = this->readUInt(); |
| 155 const void* ptr = this->skip(SkAlign4(length)); | 155 const void* ptr = this->skip(SkAlign4(length)); |
| 156 if (!fError) { | 156 if (!fError) { |
| 157 memcpy(value, ptr, length); | 157 memcpy(value, ptr, length); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 const uint32_t byteLength = count * sizeof(SkScalar); | 198 const uint32_t byteLength = count * sizeof(SkScalar); |
| 199 const void* ptr = this->skip(SkAlign4(byteLength)); | 199 const void* ptr = this->skip(SkAlign4(byteLength)); |
| 200 if (!fError) { | 200 if (!fError) { |
| 201 memcpy(values, ptr, byteLength); | 201 memcpy(values, ptr, byteLength); |
| 202 return count; | 202 return count; |
| 203 } | 203 } |
| 204 return 0; | 204 return 0; |
| 205 } | 205 } |
| 206 | 206 |
| 207 uint32_t SkValidatingReadBuffer::getArrayCount() { | 207 uint32_t SkValidatingReadBuffer::getArrayCount() { |
| 208 const size_t inc = sizeof(uint32_t); |
| 209 fError = fError || !IsPtrAlign4(fReader.peek()) || !fReader.isAvailable(inc)
; |
| 208 return *(uint32_t*)fReader.peek(); | 210 return *(uint32_t*)fReader.peek(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void SkValidatingReadBuffer::readBitmap(SkBitmap* bitmap) { | 213 void SkValidatingReadBuffer::readBitmap(SkBitmap* bitmap) { |
| 212 const int width = this->readInt(); | 214 const int width = this->readInt(); |
| 213 const int height = this->readInt(); | 215 const int height = this->readInt(); |
| 214 const size_t length = this->readUInt(); | 216 const size_t length = this->readUInt(); |
| 215 // A size of zero means the SkBitmap was simply flattened. | 217 // A size of zero means the SkBitmap was simply flattened. |
| 216 fError = fError || (length != 0); | 218 fError = fError || (length != 0); |
| 217 if (fError) { | 219 if (fError) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 delete obj; | 257 delete obj; |
| 256 obj = NULL; | 258 obj = NULL; |
| 257 } | 259 } |
| 258 } else { | 260 } else { |
| 259 // we must skip the remaining data | 261 // we must skip the remaining data |
| 260 this->skip(sizeRecorded); | 262 this->skip(sizeRecorded); |
| 261 SkASSERT(false); | 263 SkASSERT(false); |
| 262 } | 264 } |
| 263 return obj; | 265 return obj; |
| 264 } | 266 } |
| OLD | NEW |