diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 1 | ||||
-rw-r--r-- | src/core/SkReadBuffer.cpp | 16 | ||||
-rw-r--r-- | src/core/SkReadBuffer.h | 12 |
3 files changed, 19 insertions, 10 deletions
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index f28843e0d6..780cb13349 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -233,6 +233,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader, reader->readString(&key); sk_sp<SkData> data = reader->readByteArrayAsData(); BREAK_ON_READ_ERROR(reader); + SkASSERT(data); canvas->drawAnnotation(rect, key.c_str(), data.get()); } break; diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp index 48b6881b0a..adf9e64403 100644 --- a/src/core/SkReadBuffer.cpp +++ b/src/core/SkReadBuffer.cpp @@ -5,7 +5,9 @@ * found in the LICENSE file. */ +#include "SkAutoMalloc.h" #include "SkBitmap.h" +#include "SkData.h" #include "SkDeduper.h" #include "SkImage.h" #include "SkImageGenerator.h" @@ -260,6 +262,20 @@ bool SkReadBuffer::readScalarArray(SkScalar* values, size_t size) { return this->readArray(values, size, sizeof(SkScalar)); } +sk_sp<SkData> SkReadBuffer::readByteArrayAsData() { + size_t numBytes = this->getArrayCount(); + if (!this->validate(fReader.isAvailable(numBytes))) { + return nullptr; + } + + SkAutoMalloc buffer(numBytes); + if (!this->readByteArray(buffer.get(), numBytes)) { + return nullptr; + } + + return SkData::MakeFromMalloc(buffer.release(), numBytes); +} + uint32_t SkReadBuffer::getArrayCount() { const size_t inc = sizeof(uint32_t); fError = fError || !IsPtrAlign4(fReader.peek()) || !fReader.isAvailable(inc); diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index ec64e8a0b2..fd6f5d279a 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -9,7 +9,6 @@ #define SkReadBuffer_DEFINED #include "SkColorFilter.h" -#include "SkData.h" #include "SkSerialProcs.h" #include "SkDrawLooper.h" #include "SkImageFilter.h" @@ -24,6 +23,7 @@ #include "SkTHash.h" #include "SkWriteBuffer.h" +class SkData; class SkImage; class SkInflator; @@ -168,15 +168,7 @@ public: bool readPointArray(SkPoint* points, size_t size); bool readScalarArray(SkScalar* values, size_t size); - sk_sp<SkData> readByteArrayAsData() { - size_t len = this->getArrayCount(); - void* buffer = sk_malloc_throw(len); - if (!this->readByteArray(buffer, len)) { - sk_free(buffer); - return SkData::MakeEmpty(); - } - return SkData::MakeFromMalloc(buffer, len); - } + sk_sp<SkData> readByteArrayAsData(); // helpers to get info about arrays and binary data uint32_t getArrayCount(); |