mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibArchive: Use Core::Stream inside TarInputStream
This commit is contained in:
parent
71d1d9e2b5
commit
cbeaba0c12
4 changed files with 95 additions and 59 deletions
|
@ -4,23 +4,35 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibArchive/TarStream.h>
|
||||
#include <LibCore/MemoryStream.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
{
|
||||
InputMemoryStream input_stream(ReadonlyBytes { data, size });
|
||||
Archive::TarInputStream tar_stream(input_stream);
|
||||
// FIXME: Create a ReadonlyBytes variant of Core::Stream::MemoryStream.
|
||||
auto input_stream_or_error = Core::Stream::MemoryStream::construct(Bytes { const_cast<uint8_t*>(data), size });
|
||||
|
||||
if (!tar_stream.valid())
|
||||
if (input_stream_or_error.is_error())
|
||||
return 0;
|
||||
|
||||
while (!tar_stream.finished()) {
|
||||
auto const& header = tar_stream.header();
|
||||
auto tar_stream_or_error = Archive::TarInputStream::construct(input_stream_or_error.release_value());
|
||||
|
||||
if (tar_stream_or_error.is_error())
|
||||
return 0;
|
||||
|
||||
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();
|
||||
|
||||
if (!header.content_is_like_extended_header()) {
|
||||
if (tar_stream.advance().is_error())
|
||||
if (tar_stream->advance().is_error())
|
||||
return 0;
|
||||
else
|
||||
continue;
|
||||
|
@ -29,7 +41,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
|||
switch (header.type_flag()) {
|
||||
case Archive::TarFileType::GlobalExtendedHeader:
|
||||
case Archive::TarFileType::ExtendedHeader: {
|
||||
auto result = tar_stream.for_each_extended_header([&](StringView, StringView) {});
|
||||
auto result = tar_stream->for_each_extended_header([&](StringView, StringView) {});
|
||||
if (result.is_error())
|
||||
return 0;
|
||||
break;
|
||||
|
@ -38,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (tar_stream.advance().is_error())
|
||||
if (tar_stream->advance().is_error())
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue