mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
LibArchive: Pass along errors from Tar header checksum validation
This commit is contained in:
parent
fd3a823a20
commit
cb48b9bc30
2 changed files with 5 additions and 8 deletions
|
@ -94,8 +94,8 @@ ErrorOr<void> TarInputStream::load_next_header()
|
||||||
if (header_span.size() != sizeof(m_header))
|
if (header_span.size() != sizeof(m_header))
|
||||||
return Error::from_string_literal("Failed to read the entire header");
|
return Error::from_string_literal("Failed to read the entire header");
|
||||||
|
|
||||||
if (!valid())
|
if (!TRY(valid()))
|
||||||
return Error::from_string_literal("Header is not valid");
|
return Error::from_string_literal("Header has an invalid magic or checksum");
|
||||||
|
|
||||||
// Discard the rest of the header block.
|
// Discard the rest of the header block.
|
||||||
TRY(m_stream->discard(block_size - sizeof(TarFileHeader)));
|
TRY(m_stream->discard(block_size - sizeof(TarFileHeader)));
|
||||||
|
@ -103,7 +103,7 @@ ErrorOr<void> TarInputStream::load_next_header()
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TarInputStream::valid() const
|
ErrorOr<bool> TarInputStream::valid() const
|
||||||
{
|
{
|
||||||
auto const header_magic = header().magic();
|
auto const header_magic = header().magic();
|
||||||
auto const header_version = header().version();
|
auto const header_version = header().version();
|
||||||
|
@ -114,10 +114,7 @@ bool TarInputStream::valid() const
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// POSIX.1-1988 tar does not have magic numbers, so we also need to verify the header checksum.
|
// POSIX.1-1988 tar does not have magic numbers, so we also need to verify the header checksum.
|
||||||
if (header().checksum().is_error())
|
return TRY(header().checksum()) == header().expected_checksum();
|
||||||
return false;
|
|
||||||
|
|
||||||
return header().checksum().release_value() == header().expected_checksum();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TarFileStream TarInputStream::file_contents()
|
TarFileStream TarInputStream::file_contents()
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
static ErrorOr<NonnullOwnPtr<TarInputStream>> construct(NonnullOwnPtr<Core::Stream::Stream>);
|
static ErrorOr<NonnullOwnPtr<TarInputStream>> construct(NonnullOwnPtr<Core::Stream::Stream>);
|
||||||
ErrorOr<void> advance();
|
ErrorOr<void> advance();
|
||||||
bool finished() const { return m_stream->is_eof(); }
|
bool finished() const { return m_stream->is_eof(); }
|
||||||
bool valid() const;
|
ErrorOr<bool> valid() const;
|
||||||
TarFileHeader const& header() const { return m_header; }
|
TarFileHeader const& header() const { return m_header; }
|
||||||
TarFileStream file_contents();
|
TarFileStream file_contents();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue