Skip to content

Commit 3687e80

Browse files
Issue #18427: str.replace could crash the interpreter with huge strings.
This fixes two places where 'int' was used to represent the size of strings, instead of 'Py_ssize_t'. (The issue is not present in the corresponding code in the 3.x branches) Fixes #18427
1 parent f7c8584 commit 3687e80

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Misc/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #18427: str.replace could crash the interpreter with huge strings.
28+
2729
- Issue #18347: ElementTree's html serializer now preserves the case of
2830
closing tags.
2931

@@ -88,7 +90,7 @@ IDLE
8890

8991
- Issue #7136: In the Idle File menu, "New Window" is renamed "New File".
9092
Patch by Tal Einat, Roget Serwy, and Todd Rovito.
91-
93+
9294
- Issue #8515: Set __file__ when run file in IDLE.
9395
Initial patch by Bruce Frederiksen.
9496

Objects/stringobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,9 @@ string_print(PyStringObject *op, FILE *fp, int flags)
882882
size -= chunk_size;
883883
}
884884
#ifdef __VMS
885-
if (size) fwrite(data, (int)size, 1, fp);
885+
if (size) fwrite(data, (size_t)size, 1, fp);
886886
#else
887-
fwrite(data, 1, (int)size, fp);
887+
fwrite(data, 1, (size_t)size, fp);
888888
#endif
889889
Py_END_ALLOW_THREADS
890890
return 0;
@@ -2332,7 +2332,7 @@ return_self(PyStringObject *self)
23322332
}
23332333

23342334
Py_LOCAL_INLINE(Py_ssize_t)
2335-
countchar(const char *target, int target_len, char c, Py_ssize_t maxcount)
2335+
countchar(const char *target, Py_ssize_t target_len, char c, Py_ssize_t maxcount)
23362336
{
23372337
Py_ssize_t count=0;
23382338
const char *start=target;

0 commit comments

Comments
 (0)