Skip to content

Commit 97c33a6

Browse files
Pr0metheanamazon-q-developer[bot]gemini-code-assist[bot]
authored
fix: panic when reading empty extended-timestamp field (#404) (#422)
* fix: panic when reading empty extended-timestamp field (#404) * Add test assertion message Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <[email protected]> * Update src/extra_fields/extended_timestamp.rs Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <[email protected]> * Update src/extra_fields/extended_timestamp.rs Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <[email protected]> * Simplify test per Gemini suggestion --------- Signed-off-by: Chris Hennick <[email protected]> Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 8d094b8 commit 97c33a6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/extra_fields/extended_timestamp.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::result::invalid;
12
use crate::result::{ZipError, ZipResult};
23
use crate::unstable::LittleEndianReadExt;
34
use std::io::Read;
@@ -20,6 +21,9 @@ impl ExtendedTimestamp {
2021
where
2122
R: Read,
2223
{
24+
if len == 0 {
25+
return Err(invalid!("Extended timestamp field is empty"));
26+
}
2327
let mut flags = [0u8];
2428
let mut bytes_to_read = len as usize;
2529
reader.read_exact(&mut flags)?;
@@ -92,3 +96,16 @@ impl ExtendedTimestamp {
9296
self.cr_time
9397
}
9498
}
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+
}
297 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)