From c99d7c2758305e0ac5bd0cbf04a19340c91a2279 Mon Sep 17 00:00:00 2001 From: Robin Syihab Date: Mon, 4 Dec 2017 01:19:44 +0700 Subject: [PATCH] Handle invalid zip header --- src/spec.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/spec.rs b/src/spec.rs index 56f5663f..2f5466f7 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -58,6 +58,10 @@ impl CentralDirectoryEnd let search_upper_bound = file_length.checked_sub(HEADER_SIZE + ::std::u16::MAX as u64).unwrap_or(0); + if file_length < HEADER_SIZE { + return Err(ZipError::InvalidArchive("Invalid zip header")); + } + let mut pos = file_length - HEADER_SIZE; while pos >= search_upper_bound {