mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 08:56:40 +00:00
AK: Fix unsigned integer underflow in DuplexMemoryStream::write.
This commit is contained in:
parent
a34e023a33
commit
ce15c9a04c
|
@ -133,6 +133,15 @@ class WeakPtr;
|
|||
template<typename T, size_t inline_capacity = 0>
|
||||
class Vector;
|
||||
|
||||
template<typename... Parameters>
|
||||
void dbgln(const char* fmtstr, const Parameters&...);
|
||||
|
||||
template<typename... Parameters>
|
||||
void warnln(const char* fmtstr, const Parameters&...);
|
||||
|
||||
template<typename... Parameters>
|
||||
void outln(const char* fmtstr, const Parameters&...);
|
||||
|
||||
}
|
||||
|
||||
using AK::Array;
|
||||
|
|
|
@ -289,7 +289,7 @@ public:
|
|||
if ((m_write_offset + nwritten) % chunk_size == 0)
|
||||
m_chunks.append(ByteBuffer::create_uninitialized(chunk_size));
|
||||
|
||||
nwritten += bytes.copy_trimmed_to(m_chunks.last().bytes().slice(m_write_offset % chunk_size));
|
||||
nwritten += bytes.slice(nwritten).copy_trimmed_to(m_chunks.last().bytes().slice(m_write_offset % chunk_size));
|
||||
}
|
||||
|
||||
m_write_offset += nwritten;
|
||||
|
|
|
@ -208,4 +208,12 @@ TEST_CASE(offset_of_out_of_bounds)
|
|||
EXPECT(!stream.offset_of(target).has_value());
|
||||
}
|
||||
|
||||
TEST_CASE(unsigned_integer_underflow_regression)
|
||||
{
|
||||
Array<u8, DuplexMemoryStream::chunk_size + 1> buffer;
|
||||
|
||||
DuplexMemoryStream stream;
|
||||
stream << buffer;
|
||||
}
|
||||
|
||||
TEST_MAIN(MemoryStream)
|
||||
|
|
Loading…
Reference in a new issue