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

Appearance settings

Commit 644813c

Browse filesBrowse files
committed
BUG: fix heap buffer overflow in np.strings.find
1 parent 1bc8764 commit 644813c
Copy full SHA for 644813c

File tree

2 files changed

+4
-10
lines changed
Filter options

2 files changed

+4
-10
lines changed

‎numpy/_core/src/umath/string_fastsearch.h

Copy file name to clipboardExpand all lines: numpy/_core/src/umath/string_fastsearch.h
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,8 @@ preprocess(CheckedIndexer<char_type> needle, Py_ssize_t len_needle,
670670
assert(p->period + p->cut <= len_needle);
671671

672672
// Compare parts of the needle to check for periodicity.
673-
int cmp;
674-
if (std::is_same<char_type, npy_ucs4>::value) {
675-
cmp = memcmp(needle.buffer,
676-
needle.buffer + (p->period * sizeof(npy_ucs4)),
677-
(size_t) p->cut);
678-
}
679-
else {
680-
cmp = memcmp(needle.buffer, needle.buffer + p->period,
681-
(size_t) p->cut);
682-
}
673+
int cmp = memcmp(needle.buffer, needle.buffer + p->period,
674+
(size_t) p->cut);
683675
p->is_periodic = (0 == cmp);
684676

685677
// If periodic, gap is unused; otherwise, calculate period and gap.

‎numpy/_core/tests/test_strings.py

Copy file name to clipboardExpand all lines: numpy/_core/tests/test_strings.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ def test_str_len(self, in_, out, dt):
381381
None, [3, -1]),
382382
("Ae¢☃€ 😊" * 2, "😊", 0, None, 6),
383383
("Ae¢☃€ 😊" * 2, "😊", 7, None, 13),
384+
pytest.param("A" * (2 ** 17), r"[\w]+\Z", 0, None, -1,
385+
id=r"A*2**17-[\w]+\Z-MAX-0--1"),
384386
])
385387
def test_find(self, a, sub, start, end, out, dt):
386388
if "😊" in a and dt == "S":

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.