This commit is contained in:
Chris Hennick 2023-05-11 21:02:51 -07:00
parent 93a5be27ff
commit 5a11cbeaee
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74

View file

@ -1038,9 +1038,10 @@ impl<W: Write + Seek> ZipWriter<W> {
#[cfg_attr(fuzzing, allow(missing_docs))] #[cfg_attr(fuzzing, allow(missing_docs))]
pub(crate) fn validate_name(name: &String) -> ZipResult<()> { pub(crate) fn validate_name(name: &String) -> ZipResult<()> {
let bytes = name.as_bytes(); let bytes = name.as_bytes();
for (index, _) in name.match_indices("PK") { let mut current_window = [0u8; 4];
if bytes.len() >= index + 4 { for window in bytes.windows(4) {
let magic_number = (&bytes[index..]).read_u32::<LittleEndian>()?; current_window.copy_from_slice(window);
let magic_number = u32::from_le_bytes(current_window);
match magic_number { match magic_number {
spec::ZIP64_CENTRAL_DIRECTORY_END_SIGNATURE => { spec::ZIP64_CENTRAL_DIRECTORY_END_SIGNATURE => {
return Err(InvalidArchive("Filename can't contain ZIP64 end signature")); return Err(InvalidArchive("Filename can't contain ZIP64 end signature"));
@ -1053,7 +1054,6 @@ pub(crate) fn validate_name(name: &String) -> ZipResult<()> {
_ => {} _ => {}
} }
} }
}
Ok(()) Ok(())
} }