Answer chunk requests whose string fields are nil
A C# caller that leaves ChunkHash, MessageId or RecordKey null writes msgpack nil; the reference reads it back as null, treats it as blank and answers found:false. Rust now decodes nil as blank in content chunk requests, so those requests are answered with the reference bytes instead of dropped. Three nil vectors from the reference server are judged by decoding them in Rust. Record two content-plane limits in the parity scope. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
a7eb9967e9
commit
5b538aaf07
5 changed files with 90 additions and 5 deletions
File diff suppressed because one or more lines are too long
|
|
@ -85,6 +85,11 @@ to speak CultNet or participate in CultMesh.
|
|||
session the client already holds (see `src/GameCult.Mesh/docs/transport-planes.md`);
|
||||
it has no authenticated content connector, so it claims no TCP+TLS or QUIC
|
||||
content path.
|
||||
Recorded limits: a caller that passes `max_bytes = u64::MAX` to `fetch_content` gets an unbounded
|
||||
body, because the reference refuses artifacts over `int.MaxValue` bytes and Rust bounds them only by the
|
||||
caller's cap.
|
||||
`normalize_hash` matches the `sha256:` prefix ASCII-case-insensitively while C# `OrdinalIgnoreCase` may
|
||||
also match non-ASCII forms (for example `ſha256:`); unprobed, and it affects hostile input only.
|
||||
|
||||
## Expansion Work Outside The Current Parity Claim
|
||||
|
||||
|
|
|
|||
|
|
@ -1073,9 +1073,9 @@ fn parse_raw_cultnet_schema_message(input: &rmpv::Value) -> Result<CultNetMessag
|
|||
})
|
||||
}
|
||||
"cultmesh.content_chunk_request.v1" => Ok(CultNetMessage::ContentChunkRequest {
|
||||
message_id: require_legacy_string(get("messageId"), "messageId")?,
|
||||
chunk_hash: require_legacy_string(get("chunkHash"), "chunkHash")?,
|
||||
record_key: require_legacy_string(get("recordKey"), "recordKey")?,
|
||||
message_id: legacy_string_or_nil(get("messageId"), "messageId")?,
|
||||
chunk_hash: legacy_string_or_nil(get("chunkHash"), "chunkHash")?,
|
||||
record_key: legacy_string_or_nil(get("recordKey"), "recordKey")?,
|
||||
expected_size_bytes: require_legacy_i32(get("expectedSizeBytes"), "expectedSizeBytes")?,
|
||||
}),
|
||||
"cultmesh.content_chunk_response.v1" => Ok(CultNetMessage::ContentChunkResponse {
|
||||
|
|
@ -1721,6 +1721,15 @@ fn require_legacy_bytes(value: Option<&rmpv::Value>, field_name: &str) -> Result
|
|||
Ok(URL_SAFE_NO_PAD.encode(bytes))
|
||||
}
|
||||
|
||||
/// A string the reference reads back as null when its writer set it to null (msgpack nil), which its
|
||||
/// handlers treat as blank. Only content chunk requests use it: they are answered, never dropped.
|
||||
fn legacy_string_or_nil(value: Option<&rmpv::Value>, field_name: &str) -> Result<String> {
|
||||
match value {
|
||||
Some(rmpv::Value::Nil) => Ok(String::new()),
|
||||
other => require_legacy_string(other, field_name),
|
||||
}
|
||||
}
|
||||
|
||||
fn require_legacy_string(value: Option<&rmpv::Value>, field_name: &str) -> Result<String> {
|
||||
let value = value
|
||||
.and_then(rmpv::Value::as_str)
|
||||
|
|
|
|||
|
|
@ -277,7 +277,11 @@ fn rust_written_vectors_are_current() {
|
|||
#[test]
|
||||
fn reference_vectors_encode_byte_identically() {
|
||||
let local = local_vectors();
|
||||
let reference = read_vectors("content-vectors.cs-written.json");
|
||||
// The nil-field vectors are bytes only the reference writes; `nil_fields_are_answered_as_blanks` judges them.
|
||||
let reference: Vec<_> = read_vectors("content-vectors.cs-written.json")
|
||||
.into_iter()
|
||||
.filter(|(label, _, _)| !label.starts_with("nil_"))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
reference.iter().map(|(l, _, _)| l.as_str()).collect::<Vec<_>>(),
|
||||
local.iter().map(|v| v.label.as_str()).collect::<Vec<_>>(),
|
||||
|
|
@ -522,7 +526,7 @@ fn answer_serves_found_false_with_the_reference_error_spelling() {
|
|||
}
|
||||
judged += 1;
|
||||
}
|
||||
assert_eq!(judged, 13);
|
||||
assert_eq!(judged, 16);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -615,6 +619,30 @@ fn a_bad_request_is_answered_never_dropped() {
|
|||
}
|
||||
}
|
||||
|
||||
// A caller that leaves a string null writes msgpack nil. The reference reads null, treats it as blank
|
||||
// and answers; Rust decodes nil as blank so the same request gets the same answer, byte for byte.
|
||||
#[test]
|
||||
fn nil_fields_are_answered_as_blanks() {
|
||||
let (_, chunks) = pack(&body());
|
||||
let store = store(&chunks);
|
||||
let reference = read_vectors("content-vectors.cs-written.json");
|
||||
for (name, spelling) in [
|
||||
("nil_message_id", "InvalidDataException: Content chunk request requires a message identity."),
|
||||
("nil_hash", "ArgumentException: Hash must be non-empty. (Parameter 'ChunkHash')"),
|
||||
("nil_record_key", "FileNotFoundException: Content chunk is not available."),
|
||||
] {
|
||||
let find = |suffix: &str| {
|
||||
let label = format!("{name}.{suffix}");
|
||||
reference.iter().find(|(l, _, _)| *l == label).expect("vector").2.clone()
|
||||
};
|
||||
let request_bytes = find("request");
|
||||
assert!(request_bytes.contains(&0xc0), "{name}: the reference wrote nil");
|
||||
let answer = answer_content_chunk_request(&unwire(&request_bytes).expect("nil decodes"), lookup_in(&store));
|
||||
assert_eq!(wire(&answer), find("response"), "{name}: answer differs from the reference's");
|
||||
assert_eq!(response_of(&answer).4, spelling, "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
// F3: metadata keeps the order it was read in and refuses a duplicate key.
|
||||
#[test]
|
||||
fn manifest_metadata_keeps_wire_order_and_refuses_a_duplicate_key() {
|
||||
|
|
|
|||
|
|
@ -174,6 +174,19 @@ public sealed class CultMeshContentVectorTests
|
|||
AddAnswer("answer_record_key_case", Request("vector-key-case", last.ChunkHash, key.ToUpperInvariant(), last.SizeBytes));
|
||||
AddAnswer("answer_blank_record_key", Request("vector-key-blank", last.ChunkHash, " ", last.SizeBytes));
|
||||
AddAnswer("answer_double_prefix", Request("vector-double", "sha256:sha256:" + last.ChunkHash, string.Empty, last.SizeBytes));
|
||||
|
||||
// A caller that leaves a string null writes msgpack nil; the reference reads it back as null and
|
||||
// answers. These are judged by Rust decoding the reference's bytes (Rust never writes nil), so
|
||||
// they stay out of the label-matched mirror set.
|
||||
void AddNilAnswer(string name, CultMeshContentChunkRequestMessage request)
|
||||
{
|
||||
vectors.Add(new Vector(name + ".request", "request", Reencode(request)));
|
||||
vectors.Add(new Vector(name + ".response", "response", Reencode(Answer(content, request))));
|
||||
}
|
||||
|
||||
AddNilAnswer("nil_message_id", Request(null, last.ChunkHash, key, last.SizeBytes));
|
||||
AddNilAnswer("nil_hash", Request("vector-nil-hash", null, string.Empty, 100));
|
||||
AddNilAnswer("nil_record_key", Request("vector-nil-key", new string('0', 64), null, 100));
|
||||
AddResponse("response_hash_last_digit", new CultMeshContentChunkResponseMessage
|
||||
{
|
||||
MessageId = "vector-digit",
|
||||
|
|
|
|||
Loading…
Reference in a new issue