diff options
author | scroggo <scroggo@chromium.org> | 2016-04-12 07:41:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-12 07:41:22 -0700 |
commit | b8e0960de41be52b3e6c85f08fdc722925c70941 (patch) | |
tree | 3107dcb1dbb04574321c079f54d5ee36a81ee479 /third_party | |
parent | 37798fbd82a7d064c5cc1516f120546a3408044b (diff) |
Make is_ktx safer
Rather than assuming the data passed to ktx at least
KTX_FILE_IDENTIFIER_SIZE, pass the length of the data to is_ktx and
compare it.
Splitting off from crrev.com/1862133002, which no longer depends on
is_ktx.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1882593002
Review URL: https://codereview.chromium.org/1882593002
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/ktx/ktx.cpp | 7 | ||||
-rw-r--r-- | third_party/ktx/ktx.h | 6 |
2 files changed, 6 insertions, 7 deletions
diff --git a/third_party/ktx/ktx.cpp b/third_party/ktx/ktx.cpp index 32985eb374..08282db453 100644 --- a/third_party/ktx/ktx.cpp +++ b/third_party/ktx/ktx.cpp @@ -336,8 +336,9 @@ bool SkKTXFile::readKTXFile(const uint8_t* data, size_t dataLen) { return bytesLeft == 0; } -bool SkKTXFile::is_ktx(const uint8_t *data) { - return 0 == memcmp(KTX_FILE_IDENTIFIER, data, KTX_FILE_IDENTIFIER_SIZE); +bool SkKTXFile::is_ktx(const uint8_t data[], size_t size) { + return size >= KTX_FILE_IDENTIFIER_SIZE && + 0 == memcmp(KTX_FILE_IDENTIFIER, data, KTX_FILE_IDENTIFIER_SIZE); } bool SkKTXFile::is_ktx(SkStreamRewindable* stream) { @@ -349,7 +350,7 @@ bool SkKTXFile::is_ktx(SkStreamRewindable* stream) { if (!largeEnough) { return false; } - return is_ktx(buf); + return is_ktx(buf, KTX_FILE_IDENTIFIER_SIZE); } SkKTXFile::KeyValue SkKTXFile::CreateKeyValue(const char *cstrKey, const char *cstrValue) { diff --git a/third_party/ktx/ktx.h b/third_party/ktx/ktx.h index 889d5aaf87..6ff8a8bd37 100644 --- a/third_party/ktx/ktx.h +++ b/third_party/ktx/ktx.h @@ -34,9 +34,7 @@ public: // The ownership of the data remains with the caller. This class is intended // to be used as a logical wrapper around the data in order to properly // access the pixels. - SkKTXFile(SkData* data) - : fData(data), fSwapBytes(false) - { + SkKTXFile(SkData* data) : fData(data), fSwapBytes(false) { data->ref(); fValid = this->readKTXFile(fData->bytes(), fData->size()); } @@ -62,7 +60,7 @@ public: bool isRGBA8() const; bool isRGB8() const; - static bool is_ktx(const uint8_t *data); + static bool is_ktx(const uint8_t data[], size_t size); static bool is_ktx(SkStreamRewindable* stream); static bool WriteETC1ToKTX(SkWStream* stream, const uint8_t *etc1Data, |