Repository navigation
fix(core): check every payload of a two descriptor value before the count - #1418
LeeroyHannigan wants to merge 2 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
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())])); |
There was a problem hiding this comment.
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.
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:
Bpayload or aBSmember that is not base64, at any depth, gets theSerializationExceptionof a singleB.SS,N,NS,BS,M,L,NULL, whatever the member order. A payload of the wrong JSON type, such as aBOOLof"yes", is not checked.The depth limit depends on where the value is. An item attribute, a key and an
AttributeUpdatesvalue may hold one map or list less than a condition operand. A condition operand is anExpressionAttributeValuesvalue, anExpectedvalue, anAttributeValueListmember or a PartiQL parameter.The code:
crates/core/src/types/attribute_value.rs:from_memberstakes the depth of the value. For a value with two descriptors, it runs the base64 walk and thencheck_valueat that depth.visit_mapreads at depth 1, which counts the item around an attribute.crates/core/src/partiql/params.rs:check_valuechecks the payloads of a value with two descriptors inPAYLOAD_ORDER, before the count. It skips a payload thatcheck_typesrefuses alone.crates/core/src/serde_helpers.rs: theExpressionAttributeValuesdeserializer 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 aSerializationException, such as a payload of the wrong JSON type, keeps its bare text.is_serialization_textsorts these texts as the engine'sdeserialize_errorsorts them, because the core crate cannot call the engine.deserialize_operandsreads the operands ofExpected,ScanFilter,QueryFilterandKeyConditionsat depth 0. The fields of those members incrates/core/src/types/item.rsandcrates/core/src/types/query.rsuse it.crates/engine/src/lib.rsandcrates/engine/src/put_item.rs: the engine answers the null member text and the nesting text as aValidationException.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
Sstands beside anLthat holds the lists, the outerLincluded. MULTI stands for the count text,Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes. NESTING stands forNesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit.AttributeUpdatesvalueExclusiveStartKeyvalueThe provided starting key is invalid:NESTINGExpressionAttributeValuesvalue, an ExecuteStatement parameterExpectedvalue orAttributeValueListmember of PutItem, UpdateItem or DeleteItemScanFilter,QueryFilterorKeyConditionsmemberWith 31 lists every place that was sent at that depth answers MULTI, after the prefix for the start key. In UpdateItem a
:vtext comes insideExpressionAttributeValues contains invalid value: <text> for key :v.Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1149 passed, 1 ignored.cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed.cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.Lor anM. The same build answers 8 of them as DynamoDB does. With{"L": [{"S": 1}, {"S": "x", "N": "1"}]}as:v, it gives the bareSerializationExceptionthat DynamoDB and the base give. A request member of the wrong JSON type gets serde_json's error text, where the service sends its own #1012 and PutItem answers ValidationException for a set member or list element of the wrong JSON type, where DynamoDB answers SerializationException #1104 cover the texts and the order of these answers, and A null element of an L or a null member of an M answers SerializationException, where DynamoDB answersThe supplied Item contains a null AttributeValue#1432 covers the null rows.tests/test_attribute_value_validation.pyandtests/test_expression_attribute_map_validation.pyagainst that build: 213 passed. The number validation files: 22 passed.tests/test_partiql_numbers.py: 105 passed, 1 xfailed, which a build without the MongoDB crate expects.Production is +222 -74 lines, and the tests are +420 -37.
The 46 requests that still differ:
SerializationExceptionthat DynamoDB gives, with the text that a singleBgets. A B value that is not valid base64 answers serde's text in its SerializationException, where DynamoDB names the length #1189 (PR fix(core): send DynamoDB's text for a B value that does not decode #1260) gives DynamoDB's text.{"SS": [1], "N": "bob"}. DynamoDB answers theSerializationExceptionNUMBER_VALUE cannot be converted to String. ExtendDB has no check of a payload's JSON type that gives this text (A request member of the wrong JSON type gets serde_json's error text, where the service sends its own #1012).Nto UpdateItem on a table that does not exist. UpdateItem looks the table up first (UpdateItem looks the table up before it checks the numbers in ExpressionAttributeValues #1380).E200orE-200beside a second descriptor (PartiQL: check_number reports the digit count before the magnitude, and DynamoDB reports the magnitude first #958, PR fix(core): check a PartiQL number's magnitude before its digit count #1376).ExclusiveStartKey. They differ only in the prefixThe provided starting key is invalid:, which the base does not give either. fix(scan): check AttributesToGet, ScanFilter, ExclusiveStartKey and ExpressionAttributeValues in the service's order #854 adds that prefix for a Scan start key value that is not one type.This PR adds no conflict in a file where #1381 merges clean. Where #1381 conflicts already, these resolutions apply:
check_typesout ofparams.rs. Whichever of this PR and theirs merges second updates the one call ofcheck_typesincheck_value.starts_with("invalid base64: ")test inis_serialization_textbecomes a call ofis_base64_refusal.:vvalue first. On top of it,is_serialization_textmeets no<type> value must betext and no base64 text, so whichever of the two merges second can drop those two tests.put_item.rs. On top of them, drop the two lines this PR adds there.attribute_value.rstoattribute_value/tests.rs. The rows that this PR adds move with them.Closes #1404
Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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.