FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

BUG: fix heap buffer overflow in timedelta to string casts by charris · Pull Request #31206 · numpy/numpy · GitHub

/ numpy Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions numpy/_core/src/multiarray/datetime.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4071,6 +4071,9 @@ time_to_string_resolve_descriptors(
if (loop_descrs[1] == NULL) {
return -1;
}
if (given_descrs[1] != NULL) {
size = (size < given_descrs[1]->elsize) ? size : given_descrs[1]->elsize;
}
loop_descrs[1]->elsize = size;
}

Expand Down
4 changes: 4 additions & 0 deletions numpy/_core/tests/test_datetime.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,10 @@ def test_limit_str_roundtrip(self, time_unit, sign):
limit_via_str = np.datetime64(str(limit), time_unit)
assert limit_via_str == limit

def test_cast_to_truncated_string_doesnt_overflow(self):
a = np.array([1, -2, 1], dtype='timedelta64[D]')
assert_array_equal(a.astype('U1'), ['1', '-', '1'])

def test_datetime_hash_nat(self):
nat1 = np.datetime64()
nat2 = np.datetime64()
Expand Down
Loading

Back | FazBrowse Home | New Git URL