Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit51ea33c

Browse files
authored
Fix possible out of bound array access (haoel#254)
Should check array size before accessing the second to fourth bytes ofutf8 as there might be not enough data left in the array.
1 parent36168cc commit51ea33c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

‎algorithms/cpp/UTF8Validation/UTF8Validation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class Solution {
6767
returnfalse;
6868
}
6969

70+
// invalid utf-8 as it doesn't have enough 10xxxxxx
71+
if (i + len > data.size()) {
72+
returnfalse;
73+
}
7074

7175
for (int j=i+1; j < i+len; j++) {//checking 10xxxxxx
7276
if ( (data[j] &0xC0) !=0x80 ) {
@@ -75,11 +79,6 @@ class Solution {
7579
}
7680

7781
i += len ;
78-
79-
if (i > data.size()) {
80-
returnfalse;
81-
}
82-
8382
}
8483
returntrue;
8584
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp