Skip to content

Commit 0ddcffa

Browse files
guard skip_bytes in tell_impl against overflow
1 parent 64b052a commit 0ddcffa

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Modules/_io/textio.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2933,7 +2933,13 @@ _io_TextIOWrapper_tell_impl(textio *self)
29332933

29342934
/* Fast search for an acceptable start point, close to our
29352935
current pos */
2936-
skip_bytes = (Py_ssize_t) (self->b2cratio * chars_to_skip);
2936+
double skip_bytes_d = self->b2cratio * (double) chars_to_skip;
2937+
if (!(skip_bytes_d >= 0) || skip_bytes_d >= (double) PY_SSIZE_T_MAX) {
2938+
PyErr_SetString(PyExc_OverflowError,
2939+
"chars_to_skip are too large");
2940+
goto fail;
2941+
}
2942+
skip_bytes = (Py_ssize_t) skip_bytes_d;
29372943
skip_back = 1;
29382944
assert(skip_bytes <= PyBytes_GET_SIZE(next_input));
29392945
input = PyBytes_AS_STRING(next_input);

0 commit comments

Comments
 (0)