Bytes after the value: a payload is one MessagePack value (TypeScript)
decodeDocumentPayload refuses bytes after the first value by count, from the checkPayloadDepth walk's end, with the shared clause; readWire's own trailing check is deleted. Walks bytes-after-outcomes.msgpack on the plain, codec, store and putEnvelope paths. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5e10909fe9
commit
be968a71e6
7 changed files with 128 additions and 20 deletions
|
|
@ -119,7 +119,13 @@ export function decodeDocumentPayload<TDefinition extends AnyCultCacheDocumentDe
|
|||
payload: DocumentPayload,
|
||||
): CultCacheDocumentValue<TDefinition> {
|
||||
const bytes = documentPayloadBytes(payload);
|
||||
if (writesLibraryMessagePack(definition)) checkPayloadDepth(bytes, `document type "${definition.type}" payload`);
|
||||
if (writesLibraryMessagePack(definition)) {
|
||||
// A payload is exactly one MessagePack value: bytes after the first are refused by count, from the walk's end, before
|
||||
// any formatter reads; the tail is never walked or echoed. A payload that ends early stays the decoder's to refuse.
|
||||
const subject = `document type "${definition.type}" payload`;
|
||||
const end = checkPayloadDepth(bytes, subject);
|
||||
if (end !== undefined && end < bytes.length) throw new Error(`${subject} has ${bytes.length - end} bytes after its first MessagePack value.`);
|
||||
}
|
||||
const decoded = resolveDocumentFormatter(definition).decode(bytes);
|
||||
return definition.schema.parse(decoded) as CultCacheDocumentValue<TDefinition>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue