From e99c15471cedb06a858f2e70d1e7b6f870df90e9 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 20 Jul 2022 22:20:49 +1000 Subject: [PATCH] Mv central header parsing to `central_header_to_zip_file` Signed-off-by: Jiahao XU --- src/read.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/read.rs b/src/read.rs index 15210f58..e98e0a0e 100644 --- a/src/read.rs +++ b/src/read.rs @@ -651,7 +651,13 @@ pub(crate) fn central_header_to_zip_file( ) -> ZipResult { let central_header_start = reader.stream_position()?; - central_header_to_zip_file_inner(reader, archive_offset, central_header_start) + // Parse central header + let signature = reader.read_u32::()?; + if signature != spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE { + Err(ZipError::InvalidArchive("Invalid Central Directory header")) + } else { + central_header_to_zip_file_inner(reader, archive_offset, central_header_start) + } } /// Parse a central directory entry to collect the information for the file. @@ -660,12 +666,6 @@ fn central_header_to_zip_file_inner( central_header_start: u64, archive_offset: u64, ) -> ZipResult { - // Parse central header - let signature = reader.read_u32::()?; - if signature != spec::CENTRAL_DIRECTORY_HEADER_SIGNATURE { - return Err(ZipError::InvalidArchive("Invalid Central Directory header")); - } - let version_made_by = reader.read_u16::()?; let _version_to_extract = reader.read_u16::()?; let flags = reader.read_u16::()?;