mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
AK: Fix unsigned integer underflow in DuplexMemoryStream::write.
This commit is contained in:
parent
a34e023a33
commit
ce15c9a04c
Notes:
sideshowbarker
2024-07-19 00:56:39 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/ce15c9a04cd Pull-request: https://github.com/SerenityOS/serenity/pull/4371
3 changed files with 18 additions and 1 deletions
|
@ -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…
Add table
Reference in a new issue