Commit 875af624 authored by Mike Lin's avatar Mike Lin

MallocMessageBuilder::allocateSegment: don't allocate segments above the maximum serializable size

parent df2c7ec2
......@@ -242,6 +242,8 @@ MallocMessageBuilder::~MallocMessageBuilder() noexcept(false) {
}
kj::ArrayPtr<word> MallocMessageBuilder::allocateSegment(uint minimumSize) {
KJ_REQUIRE(minimumSize <= MAX_SEGMENT_WORDS, "MallocMessageBuilder asked to allocate segment above maximum serializable size.");
if (!returnedFirstSegment && !ownFirstSegment) {
kj::ArrayPtr<word> result = kj::arrayPtr(reinterpret_cast<word*>(firstSegment), nextSize);
if (result.size() >= minimumSize) {
......@@ -254,7 +256,7 @@ kj::ArrayPtr<word> MallocMessageBuilder::allocateSegment(uint minimumSize) {
ownFirstSegment = true;
}
uint size = kj::max(minimumSize, nextSize);
uint size = kj::max(minimumSize, kj::min(MAX_SEGMENT_WORDS, nextSize));
void* result = calloc(size, sizeof(word));
if (result == nullptr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment