aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ktx/ktx.cpp
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@chromium.org>2016-04-12 07:41:22 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-12 07:41:22 -0700
commitb8e0960de41be52b3e6c85f08fdc722925c70941 (patch)
tree3107dcb1dbb04574321c079f54d5ee36a81ee479 /third_party/ktx/ktx.cpp
parent37798fbd82a7d064c5cc1516f120546a3408044b (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/ktx/ktx.cpp')
-rw-r--r--third_party/ktx/ktx.cpp7
1 files changed, 4 insertions, 3 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) {