mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
LibArchive: Move loading the next tar header into a helper function
This now also validates the first header that is loaded, so we can drop the corresponding FIXME from `tar`.
This commit is contained in:
parent
cbeaba0c12
commit
fd3a823a20
Notes:
sideshowbarker
2024-07-17 17:38:29 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/fd3a823a20 Pull-request: https://github.com/SerenityOS/serenity/pull/16241 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/sin-ack ✅ Reviewed-by: https://github.com/trflynn89
@ -25,9 +25,6 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
|
||||
auto tar_stream = tar_stream_or_error.release_value();
|
||||
|
||||
if (!tar_stream->valid())
|
||||
return 0;
|
||||
|
||||
while (!tar_stream->finished()) {
|
||||
auto const& header = tar_stream->header();
|
||||
|
||||
|
@ -56,13 +56,7 @@ ErrorOr<NonnullOwnPtr<TarInputStream>> TarInputStream::construct(NonnullOwnPtr<C
|
||||
{
|
||||
auto tar_stream = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TarInputStream(move(stream))));
|
||||
|
||||
// Try and read the header.
|
||||
auto header_span = TRY(tar_stream->m_stream->read(Bytes(&tar_stream->m_header, sizeof(m_header))));
|
||||
if (header_span.size() != sizeof(m_header))
|
||||
return Error::from_string_literal("Failed to read the entire header");
|
||||
|
||||
// Discard the rest of the block.
|
||||
TRY(tar_stream->m_stream->discard(block_size - sizeof(TarFileHeader)));
|
||||
TRY(tar_stream->load_next_header());
|
||||
|
||||
return tar_stream;
|
||||
}
|
||||
@ -89,7 +83,13 @@ ErrorOr<void> TarInputStream::advance()
|
||||
TRY(m_stream->discard(block_ceiling(file_size) - m_file_offset));
|
||||
m_file_offset = 0;
|
||||
|
||||
// FIXME: This is not unlike the initial initialization. Maybe we should merge those two.
|
||||
TRY(load_next_header());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> TarInputStream::load_next_header()
|
||||
{
|
||||
auto header_span = TRY(m_stream->read(Bytes(&m_header, sizeof(m_header))));
|
||||
if (header_span.size() != sizeof(m_header))
|
||||
return Error::from_string_literal("Failed to read the entire header");
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
|
||||
private:
|
||||
TarInputStream(NonnullOwnPtr<Core::Stream::Stream>);
|
||||
ErrorOr<void> load_next_header();
|
||||
|
||||
TarFileHeader m_header;
|
||||
NonnullOwnPtr<Core::Stream::Stream> m_stream;
|
||||
|
@ -88,11 +88,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
}());
|
||||
|
||||
auto tar_stream = TRY(Archive::TarInputStream::construct(move(input_stream)));
|
||||
// FIXME: implement ErrorOr<TarInputStream>?
|
||||
if (!tar_stream->valid()) {
|
||||
warnln("the provided file is not a well-formatted ustar file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HashMap<String, String> global_overrides;
|
||||
HashMap<String, String> local_overrides;
|
||||
|
Loading…
Reference in New Issue
Block a user