mirror of
https://github.com/matrix-construct/construct
synced 2025-03-13 21:10:32 +01:00
ircd:Ⓜ️ Add event serial size check; check size during commit.
This commit is contained in:
parent
304f5422c6
commit
fa3d92103c
3 changed files with 42 additions and 17 deletions
|
@ -20,6 +20,9 @@ namespace ircd::m
|
|||
|
||||
size_t degree(const event &);
|
||||
|
||||
bool check_size(std::nothrow_t, const event &);
|
||||
void check_size(const event &);
|
||||
|
||||
std::string pretty(const event &);
|
||||
std::string pretty_oneline(const event &);
|
||||
|
||||
|
|
|
@ -36,6 +36,44 @@ ircd::m::event_id(const event &event)
|
|||
return at<"event_id"_>(event);
|
||||
}
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
conf::item<size_t> event_max_size
|
||||
{
|
||||
{ "name", "m.event.max_size" },
|
||||
{ "default", 65507L },
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::check_size(const event &event)
|
||||
{
|
||||
const size_t &event_size
|
||||
{
|
||||
serialized(event)
|
||||
};
|
||||
|
||||
if(event_size > size_t(event_max_size))
|
||||
throw m::BAD_JSON
|
||||
{
|
||||
"Event is %zu bytes which is larger than the maximum %zu bytes",
|
||||
event_size,
|
||||
size_t(event_max_size)
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::check_size(std::nothrow_t,
|
||||
const event &event)
|
||||
{
|
||||
const size_t &event_size
|
||||
{
|
||||
serialized(event)
|
||||
};
|
||||
|
||||
return event_size <= size_t(event_max_size);
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::degree(const event &event)
|
||||
{
|
||||
|
|
18
ircd/m/vm.cc
18
ircd/m/vm.cc
|
@ -169,23 +169,7 @@ ircd::m::vm::commit(json::iov &iov)
|
|||
iov
|
||||
};
|
||||
|
||||
if(unlikely(!json::get<"event_id"_>(event)))
|
||||
{
|
||||
assert(0);
|
||||
throw m::BAD_JSON
|
||||
{
|
||||
"Required event field: event_id"
|
||||
};
|
||||
}
|
||||
|
||||
if(unlikely(!json::get<"type"_>(event)))
|
||||
{
|
||||
assert(0);
|
||||
throw m::BAD_JSON
|
||||
{
|
||||
"Required event field: type"
|
||||
};
|
||||
}
|
||||
check_size(event);
|
||||
|
||||
log.debug("injecting event(mark: %ld) %s",
|
||||
vm::current_sequence,
|
||||
|
|
Loading…
Add table
Reference in a new issue