File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 88* Change to 2021 edition
99* Drop lifetime annotations of reader parameter in ` ArchiveIterator::from_read `
1010 and ` ArchiveIterator::from_read_with_encoding ` [ #90 ]
11+ * Forward name decode failures in ` ArchiveIterator::from_read ` and
12+ ` ArchiveIterator::from_read_with_encoding ` instead of panicking [ #91 ]
1113
1214## [ 0.13.0] - 2022-08-03
1315
Original file line number Diff line number Diff line change @@ -269,7 +269,10 @@ impl<R: Read + Seek> ArchiveIterator<R> {
269269 ffi:: ARCHIVE_OK | ffi:: ARCHIVE_WARN => {
270270 let _utf8_guard = ffi:: WindowsUTF8LocaleGuard :: new ( ) ;
271271 let cstr = CStr :: from_ptr ( ffi:: archive_entry_pathname ( self . archive_entry ) ) ;
272- let file_name = ( self . decode ) ( cstr. to_bytes ( ) ) . unwrap ( ) ;
272+ let file_name = match ( self . decode ) ( cstr. to_bytes ( ) ) {
273+ Ok ( f) => f,
274+ Err ( e) => return ArchiveContents :: Err ( e) ,
275+ } ;
273276 let stat = * ffi:: archive_entry_stat ( self . archive_entry ) ;
274277 ArchiveContents :: StartOfEntry ( file_name, stat)
275278 }
Original file line number Diff line number Diff line change 44
55use compress_tools:: * ;
66use std:: {
7- io:: { Cursor , Read } ,
7+ io:: { Cursor , ErrorKind , Read } ,
88 path:: Path ,
99} ;
1010
@@ -686,3 +686,19 @@ fn uncompress_archive_absolute_path() {
686686 assert ! ( correct_dest. exists( ) ) ;
687687 assert ! ( !Path :: new( incorrect_dest) . exists( ) ) ;
688688}
689+
690+ #[ test]
691+ fn decode_failure ( ) {
692+ let source = std:: fs:: File :: open ( "tests/fixtures/file.txt.gz" ) . unwrap ( ) ;
693+ let decode_fail = |_bytes : & [ u8 ] | Err ( Error :: Io ( std:: io:: Error :: from ( ErrorKind :: BrokenPipe ) ) ) ;
694+
695+ for content in ArchiveIterator :: from_read_with_encoding ( source, decode_fail) . unwrap ( ) {
696+ if let ArchiveContents :: Err ( Error :: Io ( err) ) = content {
697+ if err. kind ( ) == ErrorKind :: BrokenPipe {
698+ return ;
699+ }
700+ }
701+ }
702+
703+ panic ! ( "Did not find expected error" ) ;
704+ }
You can’t perform that action at this time.
0 commit comments