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:
parent
36168cc9e1
commit
51ea33c75c
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user