LibArchive: Read Tar archive headers through read_value

This commit is contained in:
Tim Schumacher 2023-03-01 15:51:13 +01:00 committed by Linus Groh
parent b623dda765
commit 26ba195cf6
Notes: sideshowbarker 2024-07-16 22:58:47 +09:00
2 changed files with 6 additions and 4 deletions

View file

@ -155,3 +155,8 @@ private:
};
}
template<>
struct AK::Traits<Archive::TarFileHeader> : public AK::GenericTraits<Archive::TarFileHeader> {
static constexpr bool is_trivially_serializable() { return true; }
};

View file

@ -92,10 +92,7 @@ ErrorOr<void> TarInputStream::load_next_header()
{
size_t number_of_consecutive_zero_blocks = 0;
while (true) {
// FIXME: This should read the entire span.
auto header_span = TRY(m_stream->read_some(Bytes(&m_header, sizeof(m_header))));
if (header_span.size() != sizeof(m_header))
return Error::from_string_literal("Failed to read the entire header");
m_header = TRY(m_stream->read_value<TarFileHeader>());
// Discard the rest of the header block.
TRY(m_stream->discard(block_size - sizeof(TarFileHeader)));