From dbc25f18ec6b96c28a6fab7665bfd1e159951e27 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Thu, 8 Jun 2023 19:48:05 +0200 Subject: [PATCH] LibCompress: Let `BrotliDecompressionStream` take a `MaybeOwned` --- Meta/Lagom/Fuzzers/FuzzBrotli.cpp | 2 +- Tests/LibCompress/TestBrotli.cpp | 4 ++-- Userland/Libraries/LibCompress/Brotli.cpp | 4 ++-- Userland/Libraries/LibCompress/Brotli.h | 2 +- Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp | 2 +- Userland/Libraries/LibHTTP/Job.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp index db75f5c3fd5..59bdc907e7c 100644 --- a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp +++ b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp @@ -12,7 +12,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { FixedMemoryStream bufstream { { data, size } }; - auto brotli_stream = Compress::BrotliDecompressionStream { bufstream }; + auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned { bufstream } }; (void)brotli_stream.read_until_eof(); return 0; diff --git a/Tests/LibCompress/TestBrotli.cpp b/Tests/LibCompress/TestBrotli.cpp index eed05c59eac..fcf8ed4a58e 100644 --- a/Tests/LibCompress/TestBrotli.cpp +++ b/Tests/LibCompress/TestBrotli.cpp @@ -24,7 +24,7 @@ static void run_test(StringView const file_name) DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path); auto file = MUST(Core::File::open(path_compressed, Core::File::OpenMode::Read)); - auto brotli_stream = Compress::BrotliDecompressionStream { *file }; + auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned { *file } }; auto data = MUST(brotli_stream.read_until_eof()); EXPECT_EQ(data, cmp_data); @@ -97,7 +97,7 @@ TEST_CASE(brotli_decompress_zero_one_bin) DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path); auto file = MUST(Core::File::open(path_compressed, Core::File::OpenMode::Read)); - auto brotli_stream = Compress::BrotliDecompressionStream { *file }; + auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned { *file } }; u8 buffer_raw[4096]; Bytes buffer { buffer_raw, 4096 }; diff --git a/Userland/Libraries/LibCompress/Brotli.cpp b/Userland/Libraries/LibCompress/Brotli.cpp index 3527adad013..9b7b4c4cba3 100644 --- a/Userland/Libraries/LibCompress/Brotli.cpp +++ b/Userland/Libraries/LibCompress/Brotli.cpp @@ -28,8 +28,8 @@ ErrorOr Brotli::CanonicalCode::read_symbol(LittleEndianInputBitStream& i return Error::from_string_literal("no matching code found"); } -BrotliDecompressionStream::BrotliDecompressionStream(Stream& stream) - : m_input_stream(MaybeOwned(stream)) +BrotliDecompressionStream::BrotliDecompressionStream(MaybeOwned stream) + : m_input_stream(move(stream)) { } diff --git a/Userland/Libraries/LibCompress/Brotli.h b/Userland/Libraries/LibCompress/Brotli.h index 054257aaab9..484b1c82aa6 100644 --- a/Userland/Libraries/LibCompress/Brotli.h +++ b/Userland/Libraries/LibCompress/Brotli.h @@ -111,7 +111,7 @@ public: }; public: - BrotliDecompressionStream(Stream&); + BrotliDecompressionStream(MaybeOwned); ErrorOr read_some(Bytes output_buffer) override; ErrorOr write_some(ReadonlyBytes bytes) override { return m_input_stream.write_some(bytes); } diff --git a/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp b/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp index 17f0bb7a2f8..beec7d508b1 100644 --- a/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/WOFF2/Font.cpp @@ -1000,7 +1000,7 @@ ErrorOr> Font::try_load_from_externally_owned_memory(Seekabl return Error::from_string_literal("Not enough data to read in the reported size of the compressed data"); auto compressed_stream = FixedMemoryStream(compressed_bytes); - auto brotli_stream = Compress::BrotliDecompressionStream { compressed_stream }; + auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned(compressed_stream) }; auto decompressed_table_data = TRY(brotli_stream.read_until_eof()); if (decompressed_table_data.size() != total_length_of_all_tables) return Error::from_string_literal("Size of the decompressed data is not equal to the total of the reported lengths of each table"); diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index a0810fee842..052b0c8faf2 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -75,7 +75,7 @@ static ErrorOr handle_content_encoding(ByteBuffer const& buf, Deprec dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!"); FixedMemoryStream bufstream { buf }; - auto brotli_stream = Compress::BrotliDecompressionStream { bufstream }; + auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned(bufstream) }; auto uncompressed = TRY(brotli_stream.read_until_eof()); if constexpr (JOB_DEBUG) {