mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
AK: Correct ByteBuffer::{overwrite,slice*} bounds check
This commit is contained in:
parent
7f1d3f6d62
commit
cf5941c972
Notes:
sideshowbarker
2024-07-19 07:06:39 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/cf5941c972e Pull-request: https://github.com/SerenityOS/serenity/pull/1661 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/itamar8910
@ -94,9 +94,9 @@ private:
|
||||
Wrap,
|
||||
Adopt
|
||||
};
|
||||
explicit ByteBufferImpl(size_t); // For ConstructionMode=Uninitialized
|
||||
explicit ByteBufferImpl(size_t); // For ConstructionMode=Uninitialized
|
||||
ByteBufferImpl(const void*, size_t, ConstructionMode); // For ConstructionMode=Copy
|
||||
ByteBufferImpl(void*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt
|
||||
ByteBufferImpl(void*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt
|
||||
ByteBufferImpl() {}
|
||||
|
||||
u8* m_data { nullptr };
|
||||
@ -183,10 +183,10 @@ public:
|
||||
{
|
||||
if (is_null())
|
||||
return {};
|
||||
if (offset >= this->size())
|
||||
return {};
|
||||
if (offset + size >= this->size())
|
||||
size = this->size() - offset;
|
||||
|
||||
// I cannot hand you a slice I don't have
|
||||
ASSERT(offset + size <= this->size());
|
||||
|
||||
return wrap(offset_pointer(offset), size);
|
||||
}
|
||||
|
||||
@ -194,10 +194,10 @@ public:
|
||||
{
|
||||
if (is_null())
|
||||
return {};
|
||||
if (offset >= this->size())
|
||||
return {};
|
||||
if (offset + size >= this->size())
|
||||
size = this->size() - offset;
|
||||
|
||||
// I cannot hand you a slice I don't have
|
||||
ASSERT(offset + size <= this->size());
|
||||
|
||||
return copy(offset_pointer(offset), size);
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ public:
|
||||
void overwrite(size_t offset, const void* data, size_t data_size)
|
||||
{
|
||||
// make sure we're not told to write past the end
|
||||
ASSERT(offset + data_size < size());
|
||||
ASSERT(offset + data_size <= size());
|
||||
__builtin_memcpy(this->data() + offset, data, data_size);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user