summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Meta/Lagom/Fuzzers/FuzzBrotli.cpp2
-rw-r--r--Meta/Lagom/Fuzzers/FuzzTar.cpp3
-rw-r--r--Userland/Libraries/LibCore/MemoryStream.h20
-rw-r--r--Userland/Libraries/LibHTTP/Job.cpp3
4 files changed, 22 insertions, 6 deletions
diff --git a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp
index 7b98b01eed..bd3aa2071f 100644
--- a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp
@@ -10,7 +10,7 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
- auto bufstream_result = Core::Stream::MemoryStream::construct({ const_cast<uint8_t*>(data), size });
+ auto bufstream_result = Core::Stream::MemoryStream::construct({ data, size });
if (bufstream_result.is_error()) {
dbgln("MemoryStream::construct() failed.");
return 1;
diff --git a/Meta/Lagom/Fuzzers/FuzzTar.cpp b/Meta/Lagom/Fuzzers/FuzzTar.cpp
index 1786305da4..c508faf3d0 100644
--- a/Meta/Lagom/Fuzzers/FuzzTar.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzTar.cpp
@@ -12,8 +12,7 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
- // 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 });
+ auto input_stream_or_error = Core::Stream::MemoryStream::construct({ data, size });
if (input_stream_or_error.is_error())
return 0;
diff --git a/Userland/Libraries/LibCore/MemoryStream.h b/Userland/Libraries/LibCore/MemoryStream.h
index 569eb307db..811f5e8bc2 100644
--- a/Userland/Libraries/LibCore/MemoryStream.h
+++ b/Userland/Libraries/LibCore/MemoryStream.h
@@ -22,6 +22,11 @@ public:
return adopt_nonnull_own_or_enomem<MemoryStream>(new (nothrow) MemoryStream(bytes));
}
+ static ErrorOr<NonnullOwnPtr<MemoryStream>> construct(ReadonlyBytes bytes)
+ {
+ return adopt_nonnull_own_or_enomem<MemoryStream>(new (nothrow) MemoryStream(bytes));
+ }
+
virtual bool is_eof() const override { return m_offset >= m_bytes.size(); }
virtual bool is_open() const override { return true; }
// FIXME: It doesn't make sense to close an memory stream. Therefore, we don't do anything here. Is that fine?
@@ -67,6 +72,8 @@ public:
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override
{
+ VERIFY(m_writing_enabled);
+
// FIXME: Can this not error?
auto const nwritten = bytes.copy_trimmed_to(m_bytes.slice(m_offset));
m_offset += nwritten;
@@ -81,7 +88,11 @@ public:
return true;
}
- Bytes bytes() { return m_bytes; }
+ Bytes bytes()
+ {
+ VERIFY(m_writing_enabled);
+ return m_bytes;
+ }
ReadonlyBytes bytes() const { return m_bytes; }
size_t offset() const { return m_offset; }
size_t remaining() const { return m_bytes.size() - m_offset; }
@@ -92,9 +103,16 @@ protected:
{
}
+ explicit MemoryStream(ReadonlyBytes bytes)
+ : m_bytes({ const_cast<u8*>(bytes.data()), bytes.size() })
+ , m_writing_enabled(false)
+ {
+ }
+
private:
Bytes m_bytes;
size_t m_offset { 0 };
+ bool m_writing_enabled { true };
};
}
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp
index 787eff13c6..21c65066cf 100644
--- a/Userland/Libraries/LibHTTP/Job.cpp
+++ b/Userland/Libraries/LibHTTP/Job.cpp
@@ -78,8 +78,7 @@ static Optional<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Strin
} else if (content_encoding == "br") {
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!");
- // FIXME: MemoryStream is both read and write, however we only need the read part here
- auto bufstream_result = Core::Stream::MemoryStream::construct({ const_cast<u8*>(buf.data()), buf.size() });
+ auto bufstream_result = Core::Stream::MemoryStream::construct({ buf.data(), buf.size() });
if (bufstream_result.is_error()) {
dbgln("Job::handle_content_encoding: MemoryStream::construct() failed.");
return {};