File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed
Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -254,15 +254,11 @@ 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- 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 ( _) => { }
257+ // make sure that a subsequent call exits early when there is nothing useful left to do
258+ self . done |= matches ! ( res, Err ( _) | Ok ( Status :: StreamEnd ) ) ;
259+
260+ if let Err ( e) = res {
261+ return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ;
266262 }
267263
268264 if written > 0 || data. is_empty ( ) || self . done {
@@ -315,9 +311,9 @@ mod tests {
315311 assert_eq ! ( & data[ ..] , b"" ) ;
316312 }
317313
318- // https://github.com/alexcrichton/bzip2-rs/issues/98
319314 #[ test]
320315 fn write_invalid ( ) {
316+ // see https://github.com/trifectatechfoundation/bzip2-rs/issues/98
321317 let mut d = BzDecoder :: new ( Vec :: new ( ) ) ;
322318 let e = d. write ( b"BZh\xfb " ) . unwrap_err ( ) ;
323319 assert_eq ! ( e. kind( ) , std:: io:: ErrorKind :: InvalidInput ) ;
You can’t perform that action at this time.
0 commit comments