File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -254,11 +254,17 @@ impl<W: Write> Write for BzDecoder<W> {
254254 let res = self . data . decompress_vec ( data, & mut self . buf ) ;
255255 let written = ( self . total_in ( ) - before) as usize ;
256256
257- let res = res. map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
258-
259- if res == Status :: StreamEnd {
260- self . done = true ;
257+ match res {
258+ Err ( e) => {
259+ self . done = true ;
260+ return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ;
261+ }
262+ Ok ( Status :: StreamEnd ) => {
263+ self . done = true ;
264+ }
265+ Ok ( _) => { }
261266 }
267+
262268 if written > 0 || data. is_empty ( ) || self . done {
263269 return Ok ( written) ;
264270 }
@@ -309,6 +315,14 @@ mod tests {
309315 assert_eq ! ( & data[ ..] , b"" ) ;
310316 }
311317
318+ // https://github.com/alexcrichton/bzip2-rs/issues/98
319+ #[ test]
320+ fn write_invalid ( ) {
321+ let mut d = BzDecoder :: new ( Vec :: new ( ) ) ;
322+ let e = d. write ( b"BZh\xfb " ) . unwrap_err ( ) ;
323+ assert_eq ! ( e. kind( ) , std:: io:: ErrorKind :: InvalidInput ) ;
324+ }
325+
312326 #[ test]
313327 fn qc ( ) {
314328 :: quickcheck:: quickcheck ( test as fn ( _) -> _ ) ;
You can’t perform that action at this time.
0 commit comments