summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorRummskartoffel <Rummskartoffel@protonmail.com>2022-01-15 20:14:14 +0100
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-15 22:24:19 +0200
commit4aaab80649d0e48dd47787ee48edd9cc2287b7e8 (patch)
treee543b34de73ea919fce9aeea8a5063a4d6fac401 /Userland
parent1a2f71581b0687223c47083ab57974ee80498894 (diff)
downloadserenity-4aaab80649d0e48dd47787ee48edd9cc2287b7e8.zip
unzip: Don't fail from mmap when trying to decompress empty files
Given an empty file, unzip would try to create a zero-size memory mapping of that file, which would fail with EINVAL. With this commit, attempting to unzip an empty file of course still fails, since that's not a valid PKZIP file, but it now fails for the correct reason and with the correct error message.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/unzip.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Utilities/unzip.cpp b/Userland/Utilities/unzip.cpp
index 9488ec49dd..c45a4530eb 100644
--- a/Userland/Utilities/unzip.cpp
+++ b/Userland/Utilities/unzip.cpp
@@ -100,12 +100,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 1;
}
- auto mapped_file = TRY(Core::MappedFile::map(zip_file_path));
+ RefPtr<Core::MappedFile> mapped_file;
+ ReadonlyBytes input_bytes;
+ if (st.st_size > 0) {
+ mapped_file = TRY(Core::MappedFile::map(zip_file_path));
+ input_bytes = mapped_file->bytes();
+ }
if (!quiet)
warnln("Archive: {}", zip_file_path);
- auto zip_file = Archive::Zip::try_create(mapped_file->bytes());
+ auto zip_file = Archive::Zip::try_create(input_bytes);
if (!zip_file.has_value()) {
warnln("Invalid zip file {}", zip_file_path);
return 1;