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