Skip to content

Commit f0d20b2

Browse files
committed
gh-127971: do not read past the end of a string
Fix off-by-one read beyond the end of a string.
1 parent ccad61e commit f0d20b2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Objects/stringlib/fastsearch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
595595
continue;
596596
}
597597
/* miss: check if next character is part of pattern */
598-
if (!STRINGLIB_BLOOM(mask, ss[i+1])) {
598+
if (i < w && !STRINGLIB_BLOOM(mask, ss[i+1])) {
599599
i = i + m;
600600
}
601601
else {
@@ -604,7 +604,7 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
604604
}
605605
else {
606606
/* skip: check if next character is part of pattern */
607-
if (!STRINGLIB_BLOOM(mask, ss[i+1])) {
607+
if (i < w && !STRINGLIB_BLOOM(mask, ss[i+1])) {
608608
i = i + m;
609609
}
610610
}

0 commit comments

Comments
 (0)