0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd:Ⓜ️:vm::eval: Add coarse limit to options for array evals.

This commit is contained in:
Jason Volk 2020-09-07 16:55:47 -07:00
parent 023e1341a1
commit 5c7007ebef
2 changed files with 8 additions and 2 deletions

View file

@ -328,6 +328,10 @@ struct ircd::m::vm::opts
/// reason to ever adjust this. /// reason to ever adjust this.
size_t reserve_index {1024}; size_t reserve_index {1024};
/// Coarse limit for array evals. The counter is incremented for every
/// event; both accepted and faulted.
size_t limit = -1;
/// Mask of faults that are not thrown as exceptions out of eval(). If /// Mask of faults that are not thrown as exceptions out of eval(). If
/// masked, the fault is returned from eval(). By default, the EXISTS /// masked, the fault is returned from eval(). By default, the EXISTS
/// fault is masked which means existing events won't kill eval loops. /// fault is masked which means existing events won't kill eval loops.

View file

@ -370,6 +370,8 @@ ircd::m::vm::eval::eval(const json::array &pdus,
:eval{opts} :eval{opts}
{ {
std::vector<m::event> events(begin(pdus), end(pdus)); std::vector<m::event> events(begin(pdus), end(pdus));
if(events.size() > opts.limit)
events.resize(opts.limit);
// Sort the events first to avoid complicating the evals; the events might // Sort the events first to avoid complicating the evals; the events might
// be from different rooms but it doesn't matter. // be from different rooms but it doesn't matter.
@ -411,8 +413,8 @@ ircd::m::vm::eval::operator()(const vector_view<m::event> &events)
// Conduct each eval without letting any one exception ruin things for the // Conduct each eval without letting any one exception ruin things for the
// others, including an interrupt. The only exception is a termination. // others, including an interrupt. The only exception is a termination.
size_t ret(0); size_t ret(0), i(0);
for(auto it(begin(events)); it != end(events); ++it) try for(auto it(begin(events)); it != end(events) && i < opts->limit; ++it, ++i) try
{ {
const m::event &event const m::event &event
{ {