Align JSON-RPC bounds and parsing

This commit is contained in:
jif-oai
2026-07-09 18:38:34 +01:00
parent b6a506dfc6
commit 25c1b0df49
3 changed files with 30 additions and 1 deletions
+5
View File
@@ -184,6 +184,11 @@ impl<'de> Visitor<'de> for BoundedValueVisitor<'_> {
{
let mut values = Map::new();
while let Some(key) = object.next_key::<String>()? {
if values.contains_key(&key) {
return Err(de::Error::custom(format!(
"duplicate JSON object key `{key}`"
)));
}
let value = object.next_value_seed(BoundedValueSeed {
remaining: &mut *self.remaining,
})?;
@@ -60,6 +60,19 @@ fn accepts_large_scalar_payload() -> serde_json::Result<()> {
Ok(())
}
#[test]
fn rejects_duplicate_object_keys() {
let error = serde_json::from_str::<JSONRPCMessage>(r#"{"method":"safe","method":"dangerous"}"#)
.expect_err("duplicate JSON object keys should be rejected");
assert!(
error
.to_string()
.contains("duplicate JSON object key `method`"),
"unexpected error: {error}"
);
}
#[test]
fn rejects_compact_array_heap_amplification() {
const REPRO_VALUE_COUNT: usize = 2_097_137;