From d3ed17526444a9c422ab706d7ff98ca5fd0697fd Mon Sep 17 00:00:00 2001 From: timedout Date: Tue, 22 Sep 2026 02:04:07 +0100 Subject: [PATCH] fix(stateres): Inject dummy create event when none is available I'm not sure how this doesn't cause more panics. When running an auth check on the create event during iterative auth checks, there's obviously no create event in the base state nor auth map, so the call to fetch_state() will return nothing and thus panic. This just inserts the incoming event if it's a create event and there isn't an existing one in the auth state. It's not used for the create event checks anyway so this has no effect aside from plugging the panic. --- src/core/matrix/state_res/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index 4edf0cadb..77948c323 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -809,11 +809,17 @@ async fn iterative_auth_check<'a, E, F, Fut, S>( .await; trace!(map = ?auth_state.keys().collect::>(), event_id = event.event_id().as_str(), "auth state for event"); - // If this is not a create event, we must have the room create event in - // the auth state by now. - if *event.event_type() != StateEventType::RoomCreate.into() - || event.state_key().is_none_or(|k| !k.is_empty()) + if *event.event_type() == StateEventType::RoomCreate.into() + && event.state_key().is_some_and(str::is_empty) { + // Inject the create event so that the call to auth_check doesn't + // explode. It's not used otherwise. + auth_state + .entry(StateEventType::RoomCreate.with_state_key("")) + .or_insert_with(|| event.clone()); + } else { + // If this is not a create event, we must have the room create event + // in the auth state by now. if !auth_state.contains_key(&StateEventType::RoomCreate.with_state_key("")) { return Err(Error::NotFound(format!( "m.room.create did not appear in the auth state for {}",