File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -389,10 +389,9 @@ where
389
389
match r. read ( buf) {
390
390
Ok ( 0 ) => return Ok ( g. len - start_len) ,
391
391
Ok ( n) => {
392
- // We can't let g.len overflow which would result in the vec shrinking when the function returns. In
393
- // particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
394
- // The minimal check would just be a checked_add, but this assert is a bit more precise and should be
395
- // just about the same cost.
392
+ // We can't allow bogus values from read. If it is too large, the returned vec could have its length
393
+ // set past its capacity, or if it overflows the vec could be shortened which could create an invalid
394
+ // string if this is called via read_to_string.
396
395
assert ! ( n <= buf. len( ) ) ;
397
396
g. len += n;
398
397
}
You can’t perform that action at this time.
0 commit comments