Skip to content

Commit d597175

Browse files
committed
bugfix for unaligned short strings.
1 parent a43c1fc commit d597175

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎Objects/stringlib/find_max_char.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
6363

6464
if (!_Py_IS_ALIGNED(p, ALIGNOF_SIZE_T)) {
6565
#if STRINGLIB_SIZEOF_CHAR <= 1
66-
if (!_Py_IS_ALIGNED(p, 1)) {
66+
if (!_Py_IS_ALIGNED(p, 1) && p + 1 <= _end) {
6767
value |= *p++;
6868
}
6969
#endif
7070
#if STRINGLIB_SIZEOF_CHAR <= 2
71-
if (!_Py_IS_ALIGNED(p, sizeof(uint16_t))) {
71+
if (!_Py_IS_ALIGNED(p, sizeof(uint16_t)) && p + sizeof(uint16_t) <= _end) {
7272
value |= *(const uint16_t*)p;
7373
p += sizeof(uint16_t);
7474
}
7575
#endif
7676
#if SIZEOF_SIZE_T == 8
77-
if (!_Py_IS_ALIGNED(p, sizeof(uint32_t))) {
77+
if (!_Py_IS_ALIGNED(p, sizeof(uint32_t)) && p + sizeof(uint32_t) <= _end) {
7878
value |= *(const uint32_t*)p;
7979
p += sizeof(uint32_t);
8080
}
@@ -113,6 +113,7 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end)
113113
value |= *p++;
114114
}
115115
#endif
116+
116117
#ifdef MASK_UCS2
117118
if (value & MASK_UCS2)
118119
return MAX_CHAR_UCS4;

0 commit comments

Comments
 (0)