1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

LibArchive: Make get_field_as_integral error out on non-octal input

Fixes this bug that was reported by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52493
This commit is contained in:
implicitfield 2022-11-11 18:31:45 +02:00 committed by Andrew Kaster
parent c88d8a21cc
commit 58e9262ff1
4 changed files with 54 additions and 19 deletions

View file

@ -160,12 +160,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
String absolute_path = Core::File::absolute_path(filename);
auto parent_path = LexicalPath(absolute_path).parent();
auto header_mode_or_error = header.mode();
if (header_mode_or_error.is_error())
return header_mode_or_error.release_error();
auto header_mode = header_mode_or_error.release_value();
switch (header.type_flag()) {
case Archive::TarFileType::NormalFile:
case Archive::TarFileType::AlternateNormalFile: {
MUST(Core::Directory::create(parent_path, Core::Directory::CreateDirectories::Yes));
int fd = TRY(Core::System::open(absolute_path, O_CREAT | O_WRONLY, header.mode()));
int fd = TRY(Core::System::open(absolute_path, O_CREAT | O_WRONLY, header_mode));
Array<u8, buffer_size> buffer;
size_t bytes_read;
@ -184,7 +189,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
case Archive::TarFileType::Directory: {
MUST(Core::Directory::create(parent_path, Core::Directory::CreateDirectories::Yes));
auto result_or_error = Core::System::mkdir(absolute_path, header.mode());
auto result_or_error = Core::System::mkdir(absolute_path, header_mode);
if (result_or_error.is_error() && result_or_error.error().code() != EEXIST)
return result_or_error.error();
break;