mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +00:00
AK: Fix unsigned integer underflow in DuplexMemoryStream::write.
This commit is contained in:
parent
a34e023a33
commit
ce15c9a04c
3 changed files with 18 additions and 1 deletions
|
@ -133,6 +133,15 @@ class WeakPtr;
|
||||||
template<typename T, size_t inline_capacity = 0>
|
template<typename T, size_t inline_capacity = 0>
|
||||||
class Vector;
|
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;
|
using AK::Array;
|
||||||
|
|
|
@ -289,7 +289,7 @@ public:
|
||||||
if ((m_write_offset + nwritten) % chunk_size == 0)
|
if ((m_write_offset + nwritten) % chunk_size == 0)
|
||||||
m_chunks.append(ByteBuffer::create_uninitialized(chunk_size));
|
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;
|
m_write_offset += nwritten;
|
||||||
|
|
|
@ -208,4 +208,12 @@ TEST_CASE(offset_of_out_of_bounds)
|
||||||
EXPECT(!stream.offset_of(target).has_value());
|
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)
|
TEST_MAIN(MemoryStream)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue