Fix double-deserialize during incoming pdu parsing.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-03-10 07:05:12 +00:00
parent b5b6e3f1fd
commit cd66cd843b

View File

@@ -1,14 +1,12 @@
use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId}; use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId};
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use tuwunel_core::{ use tuwunel_core::{Result, err, implement, matrix::event::gen_event_id, result::FlatOk};
Result, err, implement, matrix::event::gen_event_id_canonical_json, result::FlatOk,
};
type Parsed = (OwnedRoomId, OwnedEventId, CanonicalJsonObject); type Parsed = (OwnedRoomId, OwnedEventId, CanonicalJsonObject);
#[implement(super::Service)] #[implement(super::Service)]
pub async fn parse_incoming_pdu(&self, pdu: &RawJsonValue) -> Result<Parsed> { pub async fn parse_incoming_pdu(&self, pdu: &RawJsonValue) -> Result<Parsed> {
let value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| { let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
err!(BadServerResponse(debug_error!("Error parsing incoming event: {e} {pdu:#?}"))) err!(BadServerResponse(debug_error!("Error parsing incoming event: {e} {pdu:#?}")))
})?; })?;
@@ -25,9 +23,9 @@ pub async fn parse_incoming_pdu(&self, pdu: &RawJsonValue) -> Result<Parsed> {
.await .await
.map_err(|_| err!("Server is not in room {room_id}"))?; .map_err(|_| err!("Server is not in room {room_id}"))?;
let (event_id, value) = gen_event_id_canonical_json(pdu, &room_version_id).map_err(|e| { gen_event_id(&value, &room_version_id)
err!(Request(InvalidParam("Could not convert event to canonical json: {e}"))) .map(move |event_id| (room_id, event_id, value))
})?; .map_err(|e| {
err!(Request(InvalidParam("Could not convert event to canonical json: {e}")))
Ok((room_id, event_id, value)) })
} }