Fix possible out of bound array access (#254)

Should check array size before accessing the second to fourth bytes of
utf8 as there might be not enough data left in the array.
This commit is contained in:
Zhao Gang 2021-11-12 14:46:08 +08:00 committed by GitHub
parent 36168cc9e1
commit 51ea33c75c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,6 +67,10 @@ public:
return false;
}
// invalid utf-8 as it doesn't have enough 10xxxxxx
if (i + len > data.size()) {
return false;
}
for (int j=i+1; j < i+len; j++) { //checking 10xxxxxx
if ( (data[j] & 0xC0) != 0x80 ) {
@ -75,11 +79,6 @@ public:
}
i += len ;
if (i > data.size()) {
return false;
}
}
return true;
}