Skip to content

fix(core): check the payloads of a two descriptor value before the count - #1381

Open
LeeroyHannigan wants to merge 1 commit into
fix/980-ignored-descriptorsfrom
fix/1185-payload-before-count
Open

LeeroyHannigan wants to merge 1 commit into
fix/980-ignored-descriptorsfrom
fix/1185-payload-before-count

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

An AttributeValue with two or more type descriptors is now refused as DynamoDB refuses it. DynamoDB checks the payloads first and the count last, in a fixed order that does not follow the request's member order:

  1. a string set that holds a member twice: One or more parameter values were invalid: Input collection [a, a] contains duplicates.
  2. the N, read by the PartiQL parameter number rules: The parameter cannot be converted to a numeric value: <text>, or the overflow, underflow or digit count text
  3. a number set two of whose members have one value: Input collection contains duplicates
  4. the count: Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes

In UpdateItem and Query each of these texts comes inside a wrapper: ExpressionAttributeValues contains invalid value: <text> for key :v. In PutItem they are bare. Before, ExtendDB refused every such value for the count alone, and UpdateItem and Query sent that text without the wrapper.

The changes:

  • from_members in crates/core/src/types/attribute_value.rs runs the three payload checks, in that order, on a value that type_descriptor would refuse for two descriptors. Then the count refuses the value.
  • The payload check is payload_refusal in crates/core/src/partiql/params.rs. check_value already applied these rules to a PartiQL parameter, and it now calls payload_refusal for the N and the number set, so the rules have one copy. The string set duplicate text moves into string_set_duplicates, which string_set and the payload check share.
  • The ExpressionAttributeValues deserializer in crates/core/src/serde_helpers.rs names the key for every value with no single descriptor. It takes the deserializer's own text, in place of its copy of the empty text.
  • is_problem_message in crates/core/src/partiql/number.rs lets the engine's two error classifiers answer the number texts as a ValidationException.

The base of this PR is #1377.

Fixes #1185
Fixes #1186
Fixes #1187

Why

DynamoDB was measured in us-east-1 on 23 November 2026, on a table that does not exist. The requests were UpdateItem (SET a = :v), Query (:v unused beside the key value) and PutItem (the shape as an attribute). 91 request shapes went out twice each, with the same answer both times. Each shape with a set went out in both member orders.

Value DynamoDB on UpdateItem, Query and PutItem
{"S": "x", "N": "1"}, {"S": "x", "N": "-0.0"} the count
{"S": "x", "N": "bob"}, and the same with 0x10 or 1 The parameter cannot be converted to a numeric value: <text>
{"S": "x", "N": ""} The parameter cannot be converted to a numeric value
{"S": "x", "N": "1e9999999999"}, 1e-9999999999, 1e2147483648, 1.5e-2147483647 The parameter cannot be converted to a numeric value: <text>
{"S": "x", "N": "1e2147483647"}, 1e-131 underflow
{"S": "x", "N": "1e126"} overflow
{"S": "x", "N": <39 digits>} the digit count text
{"SS": ["a", "a"], "N": "bob"}, {"S": "x", "SS": ["a", "a"]} the string set duplicate text
{"S": "x", "NS": ["1", "1"]} the number set duplicate text
{"NS": ["1", "1"], "N": "bob"} the number text for bob

The N beside a second descriptor follows the PartiQL parameter rules. The same N alone in UpdateItem follows the classic rules: 1e9999999999 alone is an overflow, and an empty text alone gets ... a numeric value: with the colon. That reading does not change.

Forty digits with E200 or E-200 beside a second descriptor get the overflow and the underflow text from DynamoDB. This PR gives the digit count text for them. The PartiQL check order of #1376 (#958) gives DynamoDB's texts, with no change here.

Testing done

  • cargo test -p extenddb-core --lib --no-fail-fast: 1148 passed, 1 ignored, which main ignores too. cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed. cargo test -p extenddb-server --lib --no-fail-fast: 515 passed and 5 failed. The 5 are backup_store spool privacy tests, which fail on this host on every revision.
  • cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine -p extenddb-server --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • A control put back the production code of the base and kept the tests. Both new tests failed.
  • Against a release build on SQLite, 71 of the 85 measured requests in scope got the answer of DynamoDB. The base gets 7 of them. The 14 that differ are UpdateItem with a single bad N on a table that does not exist. UpdateItem looks the table up before it checks those numbers, and UpdateItem looks the table up before it checks the numbers in ExpressionAttributeValues #1380 tracks that. On a table that exists, all 58 UpdateItem and PutItem requests get the answer of DynamoDB.
  • The 64 requests of fix(core): ignore the members DynamoDB ignores in an AttributeValue #1377 against the same build: 55 match DynamoDB. Q6 and F6, {"S": "a", "N": "1"} in Query, now get the wrapper and match. No request that matched on the base changes.
  • The Python tests of AttributeValue validation, item operations, Query and Scan, and PartiQL numbers: 513 passed and 1 xfailed.
  • 75 PartiQL parameter shapes went through the parameter checks on the base and on this PR, with the same answers.
  • A principal whose policy limits dynamodb:LeadingKeys to one partition sent keys with two descriptors and a payload fault, through PutItem, GetItem and Query. ExtendDB refused all 6 requests with the payload texts, and the item of the other partition stayed as it was.
  • The last amend changed comments and one test assertion. The core tests, clippy and fmt ran on it. The server runs used the commit before it.

Production is +93 -26 and the tests are +109 -14.

These payloads beside a second descriptor were not measured, and they keep the count's text:

  • B and BS base64 faults
  • BOOL and NULL payloads
  • an empty or null set member
  • number set members that are not numbers
  • the contents of an L or M

A PartiQL parameter with two descriptors and a payload fault still gets the count's text. DynamoDB's answer for it was not measured.

Conflicts that this PR adds, with their resolutions:

#544 reads Query values on the raw body before the deserializer, and its first_fault in crates/engine/src/query_key_values.rs has its own rule for two descriptors. That rule reads the N by the classic check, so it gives the overflow and underflow texts for 1e9999999999 and 1e-9999999999 where DynamoDB answers the unconvertible text. On its rebase, a value that type_descriptor refuses can take the deserializer's text, and the copy of the rule in first_fault can go.

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.

ExtendDB refused an AttributeValue with two type descriptors for the
count alone. Three shapes show it: {"S": "x", "N": "bob"},
{"SS": ["a", "a"], "N": "bob"} and {"S": "x", "NS": ["1", "1"]}.
UpdateItem, Query and PutItem answered each with the more than one
datatypes text. UpdateItem and Query answered it bare, without the
ExpressionAttributeValues wrapper.

DynamoDB checks the payloads first and the count last. The order is
fixed and does not follow the request's member order. The measurements
ran on 2026-11-23 in us-east-1 on UpdateItem, Query and PutItem. They
cover 91 request shapes, each sent twice, and each set shape in both
member orders.

1. A string set that holds a member twice gets the text that names the
   members.
2. The N is read by the PartiQL parameter number rules, not the classic
   ones. bob, an empty text, 1e2147483648 and 1.5e-2147483647 are
   unconvertible. 1e2147483647 and 1e-131 are underflows, 1e126 is an
   overflow, and 39 digits get the digit count text. -0.0 and 1 pass to
   the count.
3. A number set two of whose members have one value gets the short
   duplicates text.
4. Only then does the count refuse the value.

In UpdateItem and Query every one of these texts, the count's too, comes
as "ExpressionAttributeValues contains invalid value: <text> for key
:v". In PutItem the texts are bare.

The deserializer now runs the three payload checks, in that order, on a
value that type_descriptor would refuse for two descriptors. It refuses
the value for the first fault before the count. The per payload check
is partiql::params::payload_refusal. check_value also calls it for the N
and the number set of a parameter, so the number rules and the duplicate
texts have one home. The string set duplicate text moves into
string_set_duplicates, which string_set and the payload check share.

The ExpressionAttributeValues deserializer names the key for every value
with no single descriptor. It takes the deserializer's own text, in
place of its copy of the empty text. The engine classifies the number
rule texts as a ValidationException through
partiql::number::is_problem_message. So PutItem and the other operations
answer the bare texts with that type.

Other payloads beside a second descriptor were not measured. They are
B, BS, BOOL, NULL, L, M, and the members of a number set that are not
numbers.
They keep the count's text. A forty digit N with an exponent beside a
second descriptor still gets the digit count text, where the service
reports the magnitude. That follows the number check order of #958.

Fixes #1185.
Fixes #1186.
Fixes #1187.

@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.

The payloads this reads before the count get the service's text at 53ae909: for a bad N, SS and NS duplicates, out-of-range exponents and the plain count, outside PartiQL, this head matches us-east-1 on 524 of 528 requests in both member orders on SQLite and PostgreSQL (the other four are an older ExclusiveStartKey wording). Of 1,680 shapes sent twice, the service answered each the same both times; this head matches 852, its base 192, the merge onto main 888 and current main 280, and the backends never differ. Five controls fail the new tests, fmt, both clippy commands, the 1.91.1 check and the core, engine and server tests are clean, CI is green on 59 of 59, and it merges onto main at 222d80a without conflict and passes the 1.94.0 check and the tests there.

One shape main and the base answer as the service does now differs (below). After the merge, main's Query check from #544 runs first, so Query with {"S":"x","N":"1e9999999999"} still gets the overflow text rather than the service's numeric text and #1187 stays open, while the Query rows of #1185 and #1186 already match on main without this. A nested ExpressionAttributeValues value now gets the payload text but without the ExpressionAttributeValues contains invalid value: ... for key :v wrapper our review of #1377 asks for (0 of 96 rows).

I will approve once a number in Unicode digits beside a second descriptor gets the count text again, PartiQL parameters read these payloads as the other readers do, and a test holds the two classifier lines.

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

PartiQL parameters still get the count text for every payload fault this fixes elsewhere: ExecuteStatement with {"S":"x","SS":["a","a"]} gets the duplicates text from the service and the count here, and 8 of the 88 claimed rows match. The body says this was not measured.

///
/// Returns the service's message for the fault.
pub(crate) fn payload_refusal(tag: &str, payload: &Value) -> Result<(), String> {
match (tag, payload) {

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.

check_text does not fold Unicode digits as main's Query check does, so PutItem {"S":"x","N":"١"} now gets The parameter cannot be converted to a numeric value: ١, where the service, the base and main give the count text (the service reads ١ as 1); five shapes answer this way.

// The service checks a string set, then an `N`, then a number set
// payload before it counts the descriptors, whatever order the
// members come in (measured 2026-11-23 on UpdateItem, Query and
// PutItem; the set shapes in both member orders). The other payloads

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.

The service reads every payload before counting, not only SS, N and NS, so "The other payloads are not read" does not hold: NULL false, N as a JSON number, bad base64, a non-numeric NS member, an empty SS, BS duplicates, a null SS member and the contents of an L or M get their own text there and the count here (96 of 616 rows match). {"S":"x","SS":["a","a",1]} now gets the duplicates text where the service gives a SerializationException, and a 40-digit number with E200 gets the digit-count text instead of the overflow text. If #1418 is where the rest lands, the comment could say so. docs/design/01-requirements.md:532 still says two or more descriptors always get the count text.

if msg.contains("parameter values were invalid")
|| msg.contains("may not be empty")
|| msg.contains("contains duplicates")
|| extenddb_core::partiql::number::is_problem_message(&msg)

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.

No test holds this classifier line or the one at lib.rs:219: removing either, or dropping one number problem from the list at number.rs:247-257, passes all core, engine and server tests, while a server built without both answers 216 more rows otherwise (PutItem {"S":"v","N":"bob"} gets SerializationException instead of ValidationException).

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