mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
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.
This commit is contained in:
parent
1a2f71581b
commit
4aaab80649
Notes:
sideshowbarker
2024-07-17 20:49:57 +09:00
Author: https://github.com/Rummskartoffel Commit: https://github.com/SerenityOS/serenity/commit/4aaab80649d Pull-request: https://github.com/SerenityOS/serenity/pull/11924 Reviewed-by: https://github.com/IdanHo ✅
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user