Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: third_party/ktx/ktx.cpp

Issue 1882593002: Make is_ktx safer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/ktx/ktx.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/ktx/ktx.cpp
diff --git a/third_party/ktx/ktx.cpp b/third_party/ktx/ktx.cpp
index 32985eb3740b220cd9b55af3052210dfdecd0340..08282db45355eb07307e87d14a357f1174ea0ab7 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) {
« no previous file with comments | « third_party/ktx/ktx.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698