Check PDU formats
This commit is contained in:
@@ -6,6 +6,7 @@ use ruma::{
|
||||
use crate::{
|
||||
Result, extract_variant, is_equal_to,
|
||||
matrix::{PduEvent, room_version},
|
||||
state_res::{self},
|
||||
};
|
||||
|
||||
pub fn into_outgoing_federation(
|
||||
@@ -95,6 +96,8 @@ pub fn from_incoming_federation(
|
||||
pdu_json.insert("event_id".into(), CanonicalJsonValue::String(event_id.into()));
|
||||
}
|
||||
|
||||
state_res::check_pdu_format(pdu_json, &room_rules.event_format)?;
|
||||
|
||||
PduEvent::from_val(pdu_json)
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,7 @@ pub fn check_pdu_format(pdu: &CanonicalJsonObject, rules: &EventFormatRules) ->
|
||||
.map_err(|e| err!(Request(BadJson("Failed to serialize canonical JSON: {e}"))))?;
|
||||
|
||||
if json.len() > MAX_PDU_BYTES {
|
||||
return Err!(Request(InvalidParam(
|
||||
"PDU is larger than maximum of {MAX_PDU_BYTES} bytes"
|
||||
)));
|
||||
return Err!(Request(TooLarge("PDU is larger than maximum of {MAX_PDU_BYTES} bytes")));
|
||||
}
|
||||
|
||||
// Check the presence, type and length of the `type` field.
|
||||
@@ -133,7 +131,7 @@ fn extract_optional_string_field<'a>(
|
||||
match object.get(field) {
|
||||
| Some(CanonicalJsonValue::String(value)) =>
|
||||
if value.len() > ID_MAX_BYTES {
|
||||
Err!(Request(InvalidParam(
|
||||
Err!(Request(TooLarge(
|
||||
"invalid `{field}` field in PDU: string length is larger than maximum of \
|
||||
{ID_MAX_BYTES} bytes"
|
||||
)))
|
||||
@@ -177,7 +175,7 @@ fn extract_required_array_field<'a>(
|
||||
match object.get(field) {
|
||||
| Some(CanonicalJsonValue::Array(value)) =>
|
||||
if value.len() > max_len {
|
||||
Err!(Request(InvalidParam(
|
||||
Err!(Request(TooLarge(
|
||||
"invalid `{field}` field in PDU: array length is larger than maximum of \
|
||||
{max_len}"
|
||||
)))
|
||||
|
||||
Reference in New Issue
Block a user