1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:17:44 +00:00

LibTar: Support ustar tar format

Since we ignore both the ustar prefix field and the gnu extended
header right now anyways, we can just accept both formats as the
rest of the header is exactly the same.
This commit is contained in:
Idan Horowitz 2021-03-13 01:32:31 +02:00 committed by Andreas Kling
parent 512431a228
commit 6c1322bdc7
2 changed files with 11 additions and 4 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Peter Elliott <pelliott@ualberta.ca>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -46,7 +47,10 @@ enum FileType {
};
constexpr size_t block_size = 512;
constexpr const char* ustar_magic = "ustar ";
constexpr const char* gnu_magic = "ustar "; // gnu format magic
constexpr const char* gnu_version = " "; // gnu format version
constexpr const char* ustar_magic = "ustar"; // ustar format magic
constexpr const char* ustar_version = "00"; // ustar format version
class Header {
public:
@ -60,8 +64,8 @@ public:
time_t timestamp() const { return get_tar_field(m_timestamp); }
FileType type_flag() const { return FileType(m_type_flag); }
const StringView link_name() const { return m_link_name; }
const StringView magic() const { return StringView(m_magic, sizeof(m_magic)); }
const StringView version() const { return StringView(m_version, sizeof(m_version)); }
const StringView magic() const { return StringView(m_magic, min(__builtin_strlen(m_magic), sizeof(m_magic))); } // in some cases this is a null terminated string, in others its not
const StringView version() const { return StringView(m_version, min(__builtin_strlen(m_version), sizeof(m_version))); } // in some cases this is a null terminated string, in others its not
const StringView owner_name() const { return m_owner_name; }
const StringView group_name() const { return m_group_name; }
int major() const { return get_tar_field(m_major); }

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Peter Elliott <pelliott@ualberta.ca>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -120,7 +121,9 @@ void TarStream::advance()
bool TarStream::valid() const
{
return header().magic() == ustar_magic;
auto& header_magic = header().magic();
auto& header_version = header().version();
return (header_magic == gnu_magic && header_version == gnu_version) || (header_magic == ustar_magic && header_version == ustar_version);
}
TarFileStream TarStream::file_contents()