Repository navigation
fix(engine): refuse a batch table value of another type before counts - #1285
LeeroyHannigan wants to merge 6 commits into
Conversation
A BatchWriteItem over 25 tables, or a BatchGetItem over 100, got the
table count clause when one table's value had another JSON type.
DynamoDB answers a SerializationException for such a request.
When the counts of a batch fail, the count check before authorization
now parses the body as the handler does. A value whose JSON type is not
the member's gets the handler's SerializationException. A missing or
null member keeps the count clause, as does the string "true" or
"false" where a boolean goes. DynamoDB answers those with the count
clause. The parse reads the body without a copy, and runs only for a
batch whose counts fail.
An attribute value of another type, such as {"S": 1}, keeps the count
clause too, where DynamoDB answers a SerializationException. The
AttributeValue reader gives a null, or a string DynamoDB accepts, the
same text as a value of another type. The check cannot tell them apart.
Measured in us-east-1 on 20 and 21 November 2026, each request sent
twice, with names of tables that do not exist.
Refs #1266. This commit leaves the BatchGetItem row, since its count
clause quotes DynamoDB's own text form of the whole request.
…first The two branches added a helper at the same place in test_batch.py. The merge keeps OTHER_ACCOUNT from the base branch, then _raw_batch from this branch.
type_fault kept the table count clause only for the strings "true" and "false" where a boolean goes. Over the table count, DynamoDB answered the count clause for a ConsistentRead of "TRUE", "True", "1", "yes", "FALSE" or "0" too. Its echo of each request read the string as a boolean (measured 2026-11-25). Before this change, those requests got a SerializationException, where #1268 gave the count clause. type_fault now keeps the count clause for each string that reads_as_boolean accepts. That function reads BOOLEAN_TEXTS, the list of strings that the Query shape check already uses, and shape_fault_first calls it too. Another string, such as "x", keeps the SerializationException, as DynamoDB answered on 2026-11-21. The unit table and the wire table get rows for "TRUE", "1", "false" and "x". Against DynamoDB, the wire table now accepts a table count clause that quotes the request map, as DynamoDB gave on 2026-11-21 and 2026-11-25. Against ExtendDB it still compares the full text. Refs #1266.
demohan
left a comment
There was a problem hiding this comment.
A batch table value of another JSON type is now refused before the counts in most shapes at 79fbe54: of 83 shapes sent twice to us-east-1 and to this head and its base on SQLite and PostgreSQL, the base matched the service's exception class on 17 and this head on 60, with no shape answered worse than on the base. The new SerializationException comes where the count clause did, after authentication and before the IAM decision (a user with no policy gets it over the counts and AccessDenied within them, as on the base), and before the foreign-account check, as on the service. Every boolean text the service reads keeps the count clause here too, on all 8 sent. All five mutations fail malformed_entries_in_order, the 7 new SerializationException wire rows fail on the base and all 11 pass against the service, fmt, clippy, 934 engine tests, the 48 cases of test_batch.py on both backends and the 1.91.1 check are clean. Every CI run at this head was cancelled. The branch conflicts with main at 222d80a in partiql/request_checks.rs, from #1215, and a resolution builds and passes 979 engine tests.
I will approve once a value of another JSON type is found wherever it sits, not only at the typed parse's first error (below).
| /// faults, so the check reads serde's fixed `invalid type: <unexpected>, | ||
| /// expected <expected>` text. | ||
| fn type_fault(operation: &str, body: &Value) -> Option<DynamoDbError> { | ||
| let e = if operation == "BatchGetItem" { |
There was a problem hiding this comment.
The typed parse stops at its first error, so a later value of another type is not seen when the first error is a boolean string, a missing member, a null or an AttributeValue fault, and since preserve_order is off, "later" means later in key order, so the answer turns on table names. On 11 such shapes the service answered SerializationException twice and this head the count clause twice: one table {"Keys":1,"ConsistentRead":"true"}; ConsistentRead "true" in t000 with 1 in t005; [{"PutRequest":{}}] before 1; {"Keys":null} or {} before 1; {"BOOL":"true"}, {"S":null} or {} before 1. An array where an object goes is reported by serde as invalid length, not invalid type, so it keeps the count clause too: 101 BatchGetItem tables with one value [], 26 BatchWriteItem tables with [[]] or [{"PutRequest":[]}], and filled arrays for structs, where the service answers SerializationException. An AttributeValue of another type ({"S":1}, which the body leaves out) gets NUMBER_VALUE cannot be converted to String there. Walking the parsed JSON for the first value of another type, rather than reading the typed parse's first error, would cover all of these and avoid the second parse: a 15.0 MB over-count BatchWriteItem peaked at 767 and 756 MB here against 632 and 631 MB on the base.
There was a problem hiding this comment.
1cc4130 replaces the typed parse with a walk of the parsed body against the members of the request. It stops at the first value of another JSON type in any table. It skips a null, a string where a boolean goes that reads_as_boolean accepts, and a member that the request does not name. An array where an object goes is a type fault there, and so is {"S": 1}.
On 2 December each of the 11 shapes in your list, and each array shape, got SerializationException from DynamoDB, both sends. I also sent each shape with the two tables swapped, and those got the same. malformed_entries_in_order has 17 new rows for them, and the wire table 19. With the production code of 57f165e, 11 of the new unit rows fail. On a fresh SQLite server, the first 15.4 MB BatchWriteItem body over the count raised the peak memory to 691112 kB at this head. At #1268's head it rose to 700452 kB, one run each.
| ); | ||
| fn malformed_entries_in_order() { | ||
| // Measured 2026-11-20 and 2026-11-21, and 2026-11-25 for rows 17 and | ||
| // 18. Rows 0 to 4, 6, 7 and 20 have the service's error type, and row 4 |
There was a problem hiding this comment.
Optional. Row 4's clause quotes the whole request map on the service today, the #1215 form, not this text. The body describes the state before 79fbe54: every boolean text keeps the count clause now, not only "true" and "false", the table has 21 rows, test_batch.py 48 tests and the wire table 11 rows, and "makes no copy of the body" no longer holds.
There was a problem hiding this comment.
Row 4 expects the quoted map form since 57f165e. Its comment in 1cc4130 says that the row has DynamoDB's text outside the quoted map, as measured on 2 December. The body now describes this head: every text of BOOLEAN_TEXTS, 38 unit rows and 66 tests in test_batch.py. It also gives the 30 rows of the wire table, and the walk, which makes no copy of the body.
…first The base now refuses a BatchWriteItem outside its counts in the quoted request map form, as DynamoDB answered on 25 Nov and 2 Dec 2026. In test_batch.py the merge keeps both imports and _raw_batch. It drops OTHER_ACCOUNT, which no test uses now. The rows of malformed_entries_in_order that expect the BatchWriteItem table count clause now expect the quoted form. In test_batch_type_fault_over_the_table_count, a BatchWriteItem count refusal goes through _assert_write_refusal. A BatchGetItem one gets ExtendDB's text by equality, and DynamoDB's quoted map goes through the new _assert_quoted, which _assert_write_refusal calls too. DynamoDB quoted the request map in these BatchGetItem refusals on 25 Nov and 2 Dec. The QUOTED escape is gone, as in the base.
type_fault read only the first error of a typed parse of the body. That
error could be a string read as a boolean, a missing or null member, or
an attribute value fault. Then a later value of another JSON type stayed
hidden, and the request kept the count clause. DynamoDB answered each of
these requests with a SerializationException on 2 Dec 2026, in either
order of the two tables.
Now type_fault walks the parsed body against the members of the request.
It stops at the first value of another JSON type. A null is an absent
member. A string that reads_as_boolean accepts is a boolean. The walk
also finds an array where an object goes, and an attribute value of
another type, such as {"S": 1}. It makes no typed copy of the body.
The unit table has 17 new rows and the wire table 19, from the
measurements of 2 Dec.
Changes since the last review
malformed_entries_in_orderwith the BatchWriteItem count clause expect that form.test_batch_type_fault_over_the_table_countchecks DynamoDB's quoted map with_assert_quoted, with no escape for a quoted answer.type_faultfinds a value of another JSON type in any table. Before, it read only the first error of a typed parse. So a boolean string, a null or an attribute value fault in an earlier table hid a type fault in a later one. It makes no typed copy of the body now.What
A BatchWriteItem over 25 tables, or a BatchGetItem over 100, can hold a value of another JSON type. It now gets a SerializationException, wherever the value sits in the request, as DynamoDB answers. Before this change, such a request got the table count clause.
When the counts of a batch fail,
check_request_item_countsincrates/engine/src/request_limits.rscallstype_fault. It walks the parsed body against the members of the request (BATCH_GET,BATCH_WRITE, andATTRIBUTE_VALUEfor the items and keys). It stops at the first value whose JSON type the member does not take. Examples are a number where a list goes, and an array where an object goes. The walk reads these as DynamoDB does:reads_as_booleanaccepts it. That is the listBOOLEAN_TEXTSfrom fix(query): check Query values against the key schema and the number rules #544, in any ASCII case.Xin{"X": "a"}, is not read.The SerializationException holds serde's text for that value, after the handler's prefix
Start of structure or map found where not expected:. The walk runs only for a batch whose counts fail, and it makes no copy of the body.The PartiQL checks walk attribute values too (
check_parameter_typesincrates/core/src/partiql/params.rs). That walk builds only with thepartiqlfeature, and it refuses{"BOOL": "true"}, which DynamoDB reads as a boolean in a batch item. So this PR does not call it.#1114 adds
boolean_textbesideBOOLEAN_TEXTSincrates/engine/src/query_key_values.rs.boolean_text(text).is_some()gives the same answer asreads_as_boolean(text). Whichever of the two PRs merges second drops its copy.The doc of
cross_account::refusenow says that a batch outside its counts gets the answer ofcheck_request_item_countsfirst.The base of this PR is #1268.
Refs #1266
Why
These are DynamoDB's answers in us-east-1 on table names that do not exist, each request sent twice with the same answer both times. Each other table holds one put request or one key. SE is SerializationException. COUNT is the ValidationException with the table count clause. The dates are 20 and 21 November and 2 December 2026, and 25 November for
"TRUE"and"1".1,{}or[1], or aPutRequest,Item,DeleteRequestorKeyof another JSON type1or{"Keys": 1}, or a key,ProjectionExpression,ConsistentRead,ExpressionAttributeNamesorAttributesToGetof another JSON type{"S": 1}[], or a BatchWriteItem request[]orPutRequest[]{"Keys": 1, "ConsistentRead": "true"}1in another, in either order{"S": null},{"BOOL": null},{"L": null},{"X": "a"},{"BOOL": "true"}or{}{"pk": {"S": null}}or{"pk": {"X": "a"}}, orConsistentRead"true","TRUE","1"or"false"ConsistentRead"x"[{}]In the COUNT rows, DynamoDB's clause quotes the whole request map, for BatchGetItem too. ExtendDB gives BatchGetItem's clause at
'RequestItems'with no map.The review of this PR sent 72 requests to DynamoDB on 20 and 21 November. With this change, 68 of them get DynamoDB's exception type from a SQLite server of this head, against 15 on #1268's head. No request that had DynamoDB's type on #1268 loses it. All 82 answers, 10 controls among them, were HTTP 400. Three of the other four are BatchGetItem tables with no
Keyswithin the counts, which #1301 changes. The fourth is an attribute{"B": "!"}that is not base64, as "Not in this PR" says.Testing done
At ef7b83c, whose tree is the tree of 1cc4130:
cargo test -p extenddb-engine --lib: 979 passed.cargo test -p extenddb-wasm-adapter: 4 passed, theparitycorpus test among them.cargo +1.97.0 fmt --all -- --check, the two clippy commands of.github/workflows/clippy.ymlwith-D warningsonextenddb-core,extenddb-engineandextenddb-server,cargo +1.97.0 clippy -p extenddb-engine --lib --no-default-features -- -D warningsandcargo +1.94.0 check --all-targetson the same crates are clean.python3 -m pytest --collect-only -qcollects 7212 tests intestsand 731 intests/python, with no error.malformed_entries_in_orderhas 38 rows. The production code of 57f165e reads the first error of a typed parse. With it, rows 21, 22, 24, 26, 28, 30 and 32 to 36 fail. The rows with the fault in the other order pass there, because there the typed parse meets the type fault first.tests/python/test_batch.py,tests/test_batch_operations.pyandtests/test_batch_write_validation_order.pypassed 111 tests on SQLite and 111 on PostgreSQL, 66 of them intest_batch.py. On SQLite,tests/test_authz_cross_account.pypassed 19.test_batch.pyagainst a server built from fix(engine): list batch table faults after the table count clause #1268's head: 23 failed and 43 passed. The 23 failures are the rows of the type fault table that expect a SerializationException.Line counts against #1268: production +131 -8, tests +287 -33.
This PR adds no conflict with an open PR. No other open PR changes
request_limits.rsortests/python/test_batch.py. This head merges with each open PR that changes another of its files with no conflict that the PR does not have with main already.Not in this PR:
{}or{"Keys": null}within the counts (BatchGetItem with no Keys or a null Keys in a table value answers SerializationException, where DynamoDB answers ValidationException at the member path #1283). fix(engine): refuse a BatchGetItem table value with no Keys by path #1301 changes that.Bvalue that is not base64, such as{"B": "!"}. DynamoDB answers a SerializationException over the counts too, and the walk takes any string forB(A batch over its counts with a B value that is not base64 gets the count clause, where DynamoDB answers SerializationException #1549).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
Breaking changes
A batch outside its counts can hold a value of another JSON type. It gets a SerializationException in place of the count clause, as the What section says. Requests within the counts get the same answers as before.
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.