We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 33b84bb commit 59b6b11Copy full SHA for 59b6b11
library/std/src/io/mod.rs
@@ -391,7 +391,14 @@ where
391
ret = Ok(g.len - start_len);
392
break;
393
}
394
- Ok(n) => g.len += n,
+ Ok(n) => {
395
+ // We can't let g.len overflow which would result in the vec shrinking when the function returns. In
396
+ // particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
397
+ // The minimal check would just be a checked_add, but this assert is a bit more precise and should be
398
+ // just about the same cost.
399
+ assert!(n <= g.buf.len() - g.len);
400
+ g.len += n;
401
+ }
402
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
403
Err(e) => {
404
ret = Err(e);
0 commit comments