Skip to content

Commit 5d51bab

Browse files
authored
Prevent potential overflow in readStringImpl (#29065)
Prevent potential int overflow in readStringImpl, which could occur if `maxBytes` is `2**63 - 2`. Resolves part of #29034 [Reviewed by @benharsh]
2 parents 531a1ab + 82eadfc commit 5d51bab

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

modules/standard/IO.chpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8111,7 +8111,7 @@ private proc readStringImpl(ch: fileReader, ref out_var: string, len: int(64)) :
81118111
// make sure to at least request 16 bytes
81128112
if requestSz < n + 16 then requestSz = n + 16;
81138113
// but don't ever ask for more bytes than maxBytes + 5
8114-
if maxBytes < max(c_ssize_t) && requestSz > maxBytes + 5 then
8114+
if maxBytes < max(c_ssize_t) - 4 && requestSz > maxBytes + 5 then
81158115
requestSz = maxBytes + 5;
81168116
(buff, buffSz) = bufferEnsureSize(buff, buffSz, requestSz);
81178117
assert(n + 5 < buffSz);

0 commit comments

Comments
 (0)