Check PDU formats

This commit is contained in:
dasha_uwu
2025-12-18 01:34:02 +05:00
committed by Jason Volk
parent c5508bba58
commit 7b2079f714
8 changed files with 35 additions and 19 deletions

View File

@@ -68,6 +68,8 @@ pub(super) async fn handle_outlier_pdu(
let room_rules = room_version::rules(room_version)?;
state_res::check_pdu_format(&pdu_json, &room_rules.event_format)?;
// Now that we have checked the signature and hashes we can make mutations and
// convert to our PduEvent type.
let event = from_incoming_federation(room_id, event_id, &mut pdu_json, &room_rules)?;

View File

@@ -52,6 +52,8 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu(
let timer = Instant::now();
let room_rules = room_version::rules(room_version)?;
state_res::check_pdu_format(&val, &room_rules.event_format)?;
// 10. Fetch missing state and auth chain events by calling /state_ids at
// backwards extremities doing all the checks in this list starting at 1.
// These are not timeline events.

View File

@@ -187,17 +187,7 @@ pub async fn create_hash_and_sign_event(
pdu.event_id = self
.services
.server_keys
.gen_id_hash_and_sign_event(&mut pdu_json, &room_version)
.map_err(|e| {
use Error::Signatures;
use ruma::signatures::Error::PduSize;
match e {
| Signatures(PduSize) => {
err!(Request(TooLarge("PDU exceeds 65535 bytes")))
},
| _ => err!(Request(Unknown(warn!("Signing event failed: {e}")))),
}
})?;
.gen_id_hash_and_sign_event(&mut pdu_json, &room_version)?;
// Room id is event id for V12+
if matches!(version_rules.room_id_format, RoomIdFormatVersion::V2)
@@ -207,6 +197,8 @@ pub async fn create_hash_and_sign_event(
pdu_json.insert("room_id".into(), CanonicalJsonValue::String(pdu.room_id.clone().into()));
}
state_res::check_pdu_format(&pdu_json, &version_rules.event_format)?;
// Generate short event id
let _shorteventid = self
.services