Skip to content

fix(core): check every payload of a two descriptor value before the count - #1418

Open
LeeroyHannigan wants to merge 2 commits into
fix/1185-payload-before-countfrom
fix/1404-payloads-before-count
Open

LeeroyHannigan wants to merge 2 commits into
fix/1185-payload-before-countfrom
fix/1404-payloads-before-count

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

An AttributeValue with two or more type descriptors is now refused as DynamoDB refuses it. The fault of a payload, of a nested value or of the depth comes before the descriptor count:

  1. A B payload or a BS member that is not base64, at any depth, gets the SerializationException of a single B.
  2. ExtendDB then checks each payload as it checks the payload of a PartiQL parameter, in the order SS, N, NS, BS, M, L, NULL, whatever the member order. A payload of the wrong JSON type, such as a BOOL of "yes", is not checked.
  3. The count comes last.

The depth limit depends on where the value is. An item attribute, a key and an AttributeUpdates value may hold one map or list less than a condition operand. A condition operand is an ExpressionAttributeValues value, an Expected value, an AttributeValueList member or a PartiQL parameter.

The code:

  • crates/core/src/types/attribute_value.rs: from_members takes the depth of the value. For a value with two descriptors, it runs the base64 walk and then check_value at that depth. visit_map reads at depth 1, which counts the item around an attribute.
  • crates/core/src/partiql/params.rs: check_value checks the payloads of a value with two descriptors in PAYLOAD_ORDER, before the count. It skips a payload that check_types refuses alone.
  • crates/core/src/serde_helpers.rs: the ExpressionAttributeValues deserializer reads its values at depth 0. It names the key for every value with no single descriptor, nested values included. A refusal that the engine answers with a SerializationException, such as a payload of the wrong JSON type, keeps its bare text. is_serialization_text sorts these texts as the engine's deserialize_error sorts them, because the core crate cannot call the engine. deserialize_operands reads the operands of Expected, ScanFilter, QueryFilter and KeyConditions at depth 0. The fields of those members in crates/core/src/types/item.rs and crates/core/src/types/query.rs use it.
  • crates/engine/src/lib.rs and crates/engine/src/put_item.rs: the engine answers the null member text and the nesting text as a ValidationException.

No error text is new. The base of this PR is #1381.

Why

DynamoDB was measured in us-east-1 on 23 and 24 November 2026. Each request went out twice, with the same answer both times. Every request named a table that does not exist, so nothing was written. #1404 and its comment give the payload rows and their order.

In the depth rows, an S stands beside an L that holds the lists, the outer L included. MULTI stands for the count text, Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes. NESTING stands for Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit.

Place of the value 32 lists 33 lists
an item attribute of PutItem or TransactWriteItems NESTING NESTING
a key of GetItem, DeleteItem, BatchGetItem or TransactGetItems NESTING NESTING
an UpdateItem AttributeUpdates value NESTING NESTING
a Scan ExclusiveStartKey value The provided starting key is invalid: NESTING the same
an UpdateItem ExpressionAttributeValues value, an ExecuteStatement parameter MULTI NESTING
an Expected value or AttributeValueList member of PutItem, UpdateItem or DeleteItem MULTI NESTING
a ScanFilter, QueryFilter or KeyConditions member MULTI NESTING

With 31 lists every place that was sent at that depth answers MULTI, after the prefix for the start key. In UpdateItem a :v text comes inside ExpressionAttributeValues contains invalid value: <text> for key :v.

Testing done

Production is +222 -74 lines, and the tests are +420 -37.

The 46 requests that still differ:

This PR adds no conflict in a file where #1381 merges clean. Where #1381 conflicts already, these resolutions apply:

Closes #1404

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

…ount

ExtendDB refused a value with two type descriptors for the count when a
payload other than SS, N or NS was faulty. Two examples are
{"S": "x", "NS": []} and {"S": "x", "L": [null]}.

DynamoDB refuses a B or BS payload that is not base64 first, at any
depth, with a SerializationException. It then checks the other payloads
in the order SS, N, NS, BS, M, L, NULL, whatever the member order. Each
payload gets the refusal it gets as a PartiQL parameter, nested values
included. A BOOL payload of the wrong JSON type does not stop these
checks. The count comes last. An item attribute, a key or an
AttributeUpdates value may hold one map or list less than a condition
operand. A condition operand is an ExpressionAttributeValues value, an
Expected value, an AttributeValueList member or a parameter. The
measurements ran on 2026-11-23 and 2026-11-24 in us-east-1, each request
twice. The operations were PutItem, UpdateItem, DeleteItem, GetItem,
BatchGetItem, BatchWriteItem, Query, Scan, TransactGetItems,
TransactWriteItems and ExecuteStatement.

from_members refuses a B or BS payload that is not base64 at any depth
as it refuses a single B. It then walks the value with the PartiQL
parameter checks at its depth. The depth of an item attribute or a key
counts the item around it. check_value checks the payloads of a
parameter with two descriptors in the same order before the count. It
skips a payload of the wrong JSON type. The ExpressionAttributeValues
deserializer reads its values at depth 0, so they may hold one map or
list more. It names the key when a value has no single descriptor or
holds such a value in an L or an M. A payload that is not base64 keeps
its bare text. deserialize_operands reads the Expected values and the
AttributeValueList members of Expected, KeyConditions, QueryFilter and
ScanFilter at depth 0 too. PutItem and the other operations answer the
null member text and the nesting text as a ValidationException.

Closes #1404
ExtendDB reads an ExpressionAttributeValues value at depth 0 when it
holds a value with two type descriptors in an L or an M. It puts the
refusal of such a value inside "ExpressionAttributeValues contains
invalid value: <text> for key :v". That wrapper also took the refusal
of a payload of the wrong JSON type in the same value. So UpdateItem
answered {"L": [{"S": 1}, {"S": "x", "N": "1"}]} as :v with a
ValidationException. DynamoDB and the base of this branch answer a
SerializationException with no wrapper.

The wrapper now leaves out each refusal that the engine answers with a
SerializationException:

- a payload of the wrong JSON type, such as "S value must be a string"
- a value that is not an object
- a B or BS payload that is not base64, the only one left out before

Where ExtendDB answers a wrong JSON type with a text of its own, as for
a number in a set, the text stays wrapped (#1012).

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every payload of a two-descriptor value is read before the count at 1546b2b, but the check's memory grows with depth times size, so a request of a few megabytes takes gigabytes (below). On 416 PutItem and UpdateItem pairs without a wrong JSON type, in both member orders, this head matches us-east-1 on 340, the other 76 differing only in the base64 text (#1189), where the base matches 92; the depth rows match in 18 places but for the ExclusiveStartKey prefix; and SQLite and PostgreSQL agree on all 4,494 answers at this head and the base, the service answering each shape the same twice. Sixteen of nineteen controls fail as they should, the pytest files pass 213 here and fail 38 on the base, fmt, clippy, the 1.91.1 check and the core and engine tests are clean, and CI is green on 59 of 59. It merges onto main at 222d80a without conflict and passes the 1.94.0 check and the tests there, but main's own Query check from #544 (query_key_values.rs:466, first_fault) then runs first, so 30 Query shapes answer otherwise than this head, 16 of them where this head is right ({"S":"x","NULL":false} gets the count text instead of the NULL text).

I will approve once the check does not copy the subtree at each level, number set members are checked in order, and the merge with main answers Query as this head does.

crates/core/src/partiql/params.rs:259

The service checks number set members in order and stops at the first duplicate, bad number or null: {"S":"x","NS":["1","1","bob"]}, ["1","1",null], ["1","1","1e9999999999"] and the nested form get the duplicates text there and on the base, and the bob or null text here, in 14 places. Moving the duplicate check first still passes every core test, so a row for each would hold the order. serde_helpers.rs is now 673 lines.

let Some(payload) = members.get(tag).filter(|payload| !payload.is_null()) else {
continue;
};
let alone = Value::Object(Map::from_iter([(tag.to_owned(), payload.clone())]));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each level of a chain of two-descriptor values keeps a full clone of its subtree alive while the check recurses. In release builds, on a fresh server, twice each: a 1 MB :v at 31 levels took 2.34 GB and 2.5 s here, 174 MB and 0.15 s on the base and 109 MB and 0.10 s on main; 2 MB took 4.65 GB, and 4 MB 9.5 GB and 11 to 12 s, against 0.6 GB and 0.6 s on the base. PutItem and ExecuteStatement cost about 2.2 GB per MB, so a body at the 16 MB limit would need about 38 GB (not sent). Accepted requests cost the same as before. Checking the payload in place, without building alone, would keep it flat. The comment above says a payload of the wrong JSON type is not checked; the service reads past only a BOOL or NULL of "yes" and answers the other eight types with SerializationException first (320 PutItem pairs), where this head gives ValidationException on 294, which is #1012's to close.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants