File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: result:: invalid;
1
2
use crate :: result:: { ZipError , ZipResult } ;
2
3
use crate :: unstable:: LittleEndianReadExt ;
3
4
use std:: io:: Read ;
@@ -20,6 +21,9 @@ impl ExtendedTimestamp {
20
21
where
21
22
R : Read ,
22
23
{
24
+ if len == 0 {
25
+ return Err ( invalid ! ( "Extended timestamp field is empty" ) ) ;
26
+ }
23
27
let mut flags = [ 0u8 ] ;
24
28
let mut bytes_to_read = len as usize ;
25
29
reader. read_exact ( & mut flags) ?;
@@ -92,3 +96,16 @@ impl ExtendedTimestamp {
92
96
self . cr_time
93
97
}
94
98
}
99
+
100
+ #[ test]
101
+ /// Ensure we don't panic or read garbage data if the field body is empty
102
+ pub fn test_bad_extended_timestamp ( ) -> ZipResult < ( ) > {
103
+ use crate :: ZipArchive ;
104
+ use std:: io:: Cursor ;
105
+
106
+ assert ! ( ZipArchive :: new( Cursor :: new( include_bytes!(
107
+ "../../tests/data/extended_timestamp_bad.zip"
108
+ ) ) )
109
+ . is_err( ) ) ;
110
+ Ok ( ( ) )
111
+ }
You can’t perform that action at this time.
0 commit comments