cultcache-ts: the payload nesting bound (256) in the one document-payload owner, so every TS payload door shares it
checkPayloadDepth is an iterative header walk run by decodeDocumentPayload before the formatter and by encodeDocumentPayload on the formatter's bytes; the two plain-decode inspection doors call it first. The plain formatter's encoder depth is set above the limit so the walk decides. Tests: the C# bounds vectors, the walk's header and scalar rules, the owner, the inspector, the legacy version inference, and the mesh network doors; test:pack:ts denies decoder-shaped exports by enumerating the packed entries. Builds and passes untested at this commit (verification runs on Yggdrasil next). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c770db6e77
commit
b69d3057a5
10 changed files with 446 additions and 15 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { resolveDocumentFormatter } from "./document-formatter";
|
||||
import { checkPayloadDepth } from "./payload-depth";
|
||||
import type {
|
||||
AnyCultCacheDocumentDefinition,
|
||||
CultCacheSchemaCatalogMember,
|
||||
|
|
@ -104,19 +105,25 @@ export function documentPayloadBytes(payload: DocumentPayload): Uint8Array {
|
|||
return payload as unknown as Uint8Array;
|
||||
}
|
||||
|
||||
export { CultCachePayloadDepthError, MAX_PAYLOAD_DEPTH } from "./payload-depth";
|
||||
|
||||
// The one reader of a document payload: through the definition's formatter, codec or plain map, then its schema. A
|
||||
// reader holds the definition or it has no business reading the bytes, so there is no definition-less form.
|
||||
export function decodeDocumentPayload<TDefinition extends AnyCultCacheDocumentDefinition>(
|
||||
definition: TDefinition,
|
||||
payload: DocumentPayload,
|
||||
): CultCacheDocumentValue<TDefinition> {
|
||||
const decoded = resolveDocumentFormatter(definition).decode(documentPayloadBytes(payload));
|
||||
const bytes = documentPayloadBytes(payload);
|
||||
checkPayloadDepth(bytes, `document type "${definition.type}" payload`);
|
||||
const decoded = resolveDocumentFormatter(definition).decode(bytes);
|
||||
return definition.schema.parse(decoded) as CultCacheDocumentValue<TDefinition>;
|
||||
}
|
||||
|
||||
// The one writer: the definition's schema first, then its formatter, codec or plain map.
|
||||
export function encodeDocumentPayload(definition: AnyCultCacheDocumentDefinition, value: unknown): DocumentPayload {
|
||||
return documentPayloadFromBytes(resolveDocumentFormatter(definition).encode(definition.schema.parse(value)));
|
||||
const bytes = resolveDocumentFormatter(definition).encode(definition.schema.parse(value));
|
||||
checkPayloadDepth(bytes, `document type "${definition.type}" value`);
|
||||
return documentPayloadFromBytes(bytes);
|
||||
}
|
||||
|
||||
// The schema members of a document: the ones it declares, else those its codec derives, else none.
|
||||
|
|
|
|||
Loading…
Reference in a new issue