mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-13 12:16:54 +00:00
fix: Cap max_depth to 50 in hierarchy endpoint
This commit is contained in:
1 file changed
+8
-1
@@ -19,6 +19,7 @@ use ruma::{
|
||||
},
|
||||
room::{JoinRuleSummary, RestrictedSummary, RoomSummary},
|
||||
serde::Raw,
|
||||
uint,
|
||||
};
|
||||
|
||||
use crate::{Dep, rooms, sending};
|
||||
@@ -188,6 +189,12 @@ impl Service {
|
||||
// This function traverses the space hierarchy tree depth-first as required by
|
||||
// the specification.
|
||||
|
||||
// Limit max depth to 50 to keep cycles in the space graph from blowing up the
|
||||
// traversal. If you actually have over fifty nested spaces, and you're
|
||||
// looking at this function to figure out what the issue is, I suggest
|
||||
// you reconsider some of the choices you made which led you to this point.
|
||||
let max_depth = max_depth.unwrap_or_else(|| uint!(50));
|
||||
|
||||
// Check accessibility of the root room first, because we need to error out
|
||||
// if it isn't accessible.
|
||||
// TODO refactor this once the Try trait is stable
|
||||
@@ -259,7 +266,7 @@ impl Service {
|
||||
reason = "queue.len() should never be large enough to cause strange behavior \
|
||||
here"
|
||||
)]
|
||||
if max_depth.is_some_and(|max_depth| (queue.len() as u64 + 1) > max_depth.into()) {
|
||||
if (queue.len() as u64 + 1) > max_depth.into() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user