Skip to content

Commit 41f8e9f

Browse files
committed
fix #37
1 parent 3014337 commit 41f8e9f

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "brotli"
3-
version = "3.1.7"
3+
version = "3.1.8"
44
authors = ["Daniel Reiter Horn <danielrh@dropbox.com>", "The Brotli Authors"]
55
description = "A brotli compressor and decompressor that with an interface avoiding the rust stdlib. This makes it suitable for embedded devices and kernels. It is designed with a pluggable allocator so that the standard lib's allocator may be employed. The default build also includes a stdlib allocator and stream interface. Disable this with --features=no-stdlib. All included code is safe."
66
license = "BSD-3-Clause/MIT"
@@ -23,6 +23,7 @@ name = "catbrotli"
2323

2424
[profile.release]
2525
lto=true
26+
incremental=false
2627

2728
[dependencies]
2829
"alloc-no-stdlib" = {version="2.0"}

src/bin/integration_tests.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,3 +1238,38 @@ fn test_empty18() {
12381238
65536,
12391239
65536);
12401240
}
1241+
1242+
pub struct SoonErrorReader(&'static[u8], bool);
1243+
impl std::io::Read for SoonErrorReader {
1244+
fn read(&mut self, data:&mut [u8]) -> std::io::Result<usize> {
1245+
let first = self.1;
1246+
self.1 = false;
1247+
if first {
1248+
let len = core::cmp::min(self.0.len(),data.len());
1249+
data[..len].clone_from_slice(&self.0[..len]);
1250+
return Ok(len);
1251+
}
1252+
Err(io::Error::new(io::ErrorKind::PermissionDenied, "err"))
1253+
}
1254+
}
1255+
#[test]
1256+
fn test_error_returned() {
1257+
static onetwothreefourfive: [u8;5] = [1,2,3,4,5];
1258+
let params = super::brotli::enc::BrotliEncoderParams::default();
1259+
let mut erroring = SoonErrorReader(&onetwothreefourfive[..], true);
1260+
let mut br = UnlimitedBuffer::new(&[]);
1261+
let dict = &[];
1262+
let err = super::compress(&mut erroring, &mut br, 4096, &params, dict, 1);
1263+
if let Ok(_x) = err {
1264+
panic!("Should have errored {:?}\n", err);
1265+
}
1266+
let mut output = UnlimitedBuffer::new(&[]);
1267+
let mut br_copy = Buffer::new(&br.data[..]);
1268+
assert_eq!(br.data.len(),9);
1269+
match decompress_internal(&mut br_copy, &mut output, 1, 1, &mut Passthrough{}) {
1270+
Ok(_) => {}
1271+
Err(e) => panic!("Error {:?}", e),
1272+
}
1273+
assert_eq!(output.data, &onetwothreefourfive[..]);
1274+
}
1275+

src/bin/test_custom_dict.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static RANDOM_THEN_UNICODE : &'static [u8] = include_bytes!("../../testdata/rand
1111
static ALICE: &'static[u8] = include_bytes!("../../testdata/alice29.txt");
1212
use super::Rebox;
1313

14+
1415
#[test]
1516
fn test_custom_dict() {
1617
let mut raw = UnlimitedBuffer::new(ALICE);

src/enc/mod.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub fn BrotliCompressCustomIoCustomDict<ErrType,
232232
let mut next_in_offset: usize = 0;
233233
let mut next_out_offset: usize = 0;
234234
let mut total_out = Some(0usize);
235+
let mut read_err: Result<(), ErrType> = Ok(());
235236
{
236237
let s = &mut s_orig;
237238

@@ -246,7 +247,8 @@ pub fn BrotliCompressCustomIoCustomDict<ErrType,
246247
if available_in == 0 && !eof {
247248
next_in_offset = 0;
248249
match r.read(input_buffer) {
249-
Err(_) => {
250+
Err(e) => {
251+
read_err = Err(e);
250252
available_in = 0;
251253
eof = true;
252254
},
@@ -281,7 +283,13 @@ pub fn BrotliCompressCustomIoCustomDict<ErrType,
281283
next_out_offset = 0;
282284
while next_out_offset < lim {
283285
match w.write(&mut output_buffer[next_out_offset..lim]) {
284-
Err(e) => return Err(e),
286+
Err(e) => {
287+
BrotliEncoderDestroyInstance(s);
288+
if let Err(err) = read_err {
289+
return Err(err);
290+
}
291+
return Err(e);
292+
}
285293
Ok(size) => {
286294
next_out_offset += size;
287295
}
@@ -291,14 +299,20 @@ pub fn BrotliCompressCustomIoCustomDict<ErrType,
291299
next_out_offset = 0;
292300
}
293301
if result <= 0 {
294-
return Err(unexpected_eof_error_constant);
302+
if let Ok(_) = read_err {
303+
read_err = Err(unexpected_eof_error_constant);
304+
}
305+
break;
295306
}
296307
if fin != 0 {
297308
break;
298309
}
299310
}
300311
BrotliEncoderDestroyInstance(s);
301312
}
313+
if let Err(err) = read_err {
314+
return Err(err)
315+
}
302316
Ok(total_out.unwrap())
303317
}
304318

0 commit comments

Comments
 (0)