aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-12-07 13:47:24 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-08 17:22:00 +0000
commit34e368af276dc9931c46afc3cde23d20728fc882 (patch)
treec5f413735cfde61b4833582039ceaec6594fc872 /src/core
parentc465d13e6fca5e171bde45d35b2dd43117f4702e (diff)
enforce 4-byte alignment and length for buffers
Bug:792859 Change-Id: Ib4cde1015429153709956d4ffc2d4321decb79b0 Reviewed-on: https://skia-review.googlesource.com/82160 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkReadBuffer.cpp26
-rw-r--r--src/core/SkReadBuffer.h2
2 files changed, 8 insertions, 20 deletions
diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp
index 78071ee227..e3651cc3a2 100644
--- a/src/core/SkReadBuffer.cpp
+++ b/src/core/SkReadBuffer.cpp
@@ -63,7 +63,7 @@ SkReadBuffer::SkReadBuffer() {
SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
fFlags = default_flags();
fVersion = 0;
- fReader.setMemory(data, size);
+ this->setMemory(data, size);
fMemoryPtr = nullptr;
fTFArray = nullptr;
@@ -76,28 +76,16 @@ SkReadBuffer::SkReadBuffer(const void* data, size_t size) {
#endif // DEBUG_NON_DETERMINISTIC_ASSERT
}
-SkReadBuffer::SkReadBuffer(SkStream* stream) {
- fFlags = default_flags();
- fVersion = 0;
- const size_t length = stream->getLength();
- fMemoryPtr = sk_malloc_throw(length);
- stream->read(fMemoryPtr, length);
- fReader.setMemory(fMemoryPtr, length);
-
- fTFArray = nullptr;
- fTFCount = 0;
-
- fFactoryArray = nullptr;
- fFactoryCount = 0;
-#ifdef DEBUG_NON_DETERMINISTIC_ASSERT
- fDecodedBitmapIndex = -1;
-#endif // DEBUG_NON_DETERMINISTIC_ASSERT
-}
-
SkReadBuffer::~SkReadBuffer() {
sk_free(fMemoryPtr);
}
+void SkReadBuffer::setMemory(const void* data, size_t size) {
+ this->validate(IsPtrAlign4(data) && (SkAlign4(size) == size));
+ if (!fError) {
+ fReader.setMemory(data, size);
+ }
+}
void SkReadBuffer::setInvalid() {
if (!fError) {
// When an error is found, send the read cursor to the end of the stream
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index 78038aa7af..6819c47904 100644
--- a/src/core/SkReadBuffer.h
+++ b/src/core/SkReadBuffer.h
@@ -36,7 +36,6 @@ class SkReadBuffer {
public:
SkReadBuffer();
SkReadBuffer(const void* data, size_t size);
- SkReadBuffer(SkStream* stream);
virtual ~SkReadBuffer();
virtual SkReadBuffer* clone(const void* data, size_t size) const {
@@ -276,6 +275,7 @@ protected:
private:
void setInvalid();
bool readArray(void* value, size_t size, size_t elementSize);
+ void setMemory(const void*, size_t);
uint32_t fFlags;
int fVersion;