Skip to content

Commit

Permalink
Return EOF error if writer returns Ok(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz authored and danielrh committed May 27, 2024
1 parent 62daa80 commit c5c93d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ pub fn BrotliDecompressCustomIoCustomDict<ErrType,
Err(e) => {
return Result::Err(e);
},
Ok(0) => {
return Result::Err(unexpected_eof_error_constant);
}
Ok(cur_written) => {
assert_eq!(cur_written == 0, false); // not allowed by the contract
total_written += cur_written;
}
}
Expand Down Expand Up @@ -280,8 +282,10 @@ pub fn BrotliDecompressCustomIoCustomDict<ErrType,
return Result::Err(e);
},
// CustomResult::Transient(e) => continue,
Ok(0) => {
return Result::Err(unexpected_eof_error_constant);
}
Ok(cur_written) => {
assert_eq!(cur_written == 0, false); // not allowed by the contract
total_written += cur_written;
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,18 @@ fn test_early_eof() {
}
assert_eq!(input_offset, input.len());
}

#[test]
#[cfg(feature="std")]
fn test_run_out_of_writer_space() {
// this is a valid compression of [0u8; 2048];
let compression = [27, 255, 7, 0, 36, 0, 194, 177, 64, 114, 7];
// output buffer doesn't have enough space
let mut output_buffer = [0u8; 2047];

super::BrotliDecompress(
&mut io::Cursor::new(compression),
&mut io::Cursor::new(&mut output_buffer[..]),
)
.unwrap_err();
}

0 comments on commit c5c93d9

Please sign in to comment.