File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -474,13 +474,14 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(
474
474
}
475
475
476
476
let mut cursor = read_buf. unfilled ( ) ;
477
- loop {
477
+ let result = loop {
478
478
match r. read_buf ( cursor. reborrow ( ) ) {
479
- Ok ( ( ) ) => break ,
480
479
Err ( e) if e. is_interrupted ( ) => continue ,
481
- Err ( e) => return Err ( e) ,
480
+ // Do not stop now in case of error: we might have received both data
481
+ // and an error
482
+ res => break res,
482
483
}
483
- }
484
+ } ;
484
485
485
486
let unfilled_but_initialized = cursor. init_ref ( ) . len ( ) ;
486
487
let bytes_read = cursor. written ( ) ;
@@ -496,15 +497,18 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(
496
497
consecutive_short_reads = 0 ;
497
498
}
498
499
499
- // store how much was initialized but not filled
500
- initialized = unfilled_but_initialized;
501
-
502
500
// SAFETY: BorrowedBuf's invariants mean this much memory is initialized.
503
501
unsafe {
504
502
let new_len = bytes_read + buf. len ( ) ;
505
503
buf. set_len ( new_len) ;
506
504
}
507
505
506
+ // Now that all data is pushed to the vector, we can fail without data loss
507
+ result?;
508
+
509
+ // store how much was initialized but not filled
510
+ initialized = unfilled_but_initialized;
511
+
508
512
// Use heuristics to determine the max read size if no initial size hint was provided
509
513
if size_hint. is_none ( ) {
510
514
// The reader is returning short reads but it doesn't call ensure_init().
You can’t perform that action at this time.
0 commit comments