From fa94a56ea020549685fc9d26862d0dbafbd68cbd Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:31:41 +0200 Subject: [PATCH] fix Unzip::extract failing if the extractable file is empty --- loader/src/utils/file.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/loader/src/utils/file.cpp b/loader/src/utils/file.cpp index 18cf78e0..0fdc5d7d 100644 --- a/loader/src/utils/file.cpp +++ b/loader/src/utils/file.cpp @@ -295,6 +295,11 @@ public: .expect("Unable to open entry (code {error})") ); + // if the file is empty, its data is empty (duh) + if (!entry.uncompressedSize) { + return Ok(ByteVector()); + } + ByteVector res; res.resize(entry.uncompressedSize); auto read = mz_zip_entry_read(m_handle, res.data(), entry.uncompressedSize); @@ -421,11 +426,11 @@ bool Unzip::hasEntry(Path const& name) { } Result Unzip::extract(Path const& name) { - return m_impl->extract(name); + return m_impl->extract(name).expect("{error} (entry {})", name.string()); } Result<> Unzip::extractTo(Path const& name, Path const& path) { - GEODE_UNWRAP_INTO(auto bytes, m_impl->extract(name)); + GEODE_UNWRAP_INTO(auto bytes, m_impl->extract(name).expect("{error} (entry {})", name.string())); // create containing directories for target path if (path.has_parent_path()) { GEODE_UNWRAP(file::createDirectoryAll(path.parent_path()));