Skip to content

fix(core): refuse the list indexes DynamoDB refuses in expression paths - #1095

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1047-list-index-range
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1047-list-index-range

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

A list index in a document path is now refused as DynamoDB refuses it, in projection, update, condition, filter and key condition expressions.

  • An index above 2147483647 gets List index is not within the allowable range; index: [<n>]. The text gives the index as the request wrote it. With two or more such indexes, it names the first one.
  • An index of two or more digits that starts with 0 is a syntax error, for example Syntax error; token: "1", near: "01]" for l[01].
  • A syntax error anywhere in the expression comes ahead of the range refusal.
  • UpdateItem, PutItem and DeleteItem put 1 validation error detected: ahead of both refusals. TransactWriteItems and the reads do not.
  • PartiQL refuses an index above 2147483647 with the same sentence, followed by the number's line, column and length. For SELECT l[2147483648] FROM "t" WHERE pk = 'k' the text ends in at 1:10:10.

parse_path refuses a leading zero as it reads the path. Once the whole expression parses, check_list_indexes scans its tokens and refuses the first index that does not fit in an i32. The range sentence comes from one function, list_index_range_refusal, which the PartiQL parser calls too. count_list_index_refusal adds the count at the two places where the single-item writes parse their expressions. It also applies to a syntax error of the tokenizer on these writes, such as SET a = $, as on DynamoDB.

Why

These are DynamoDB's answers, measured in us-east-1. The issue's rows were measured on 13 and 14 November 2026. The other expression kinds, TransactWriteItems, the conditions of DeleteItem and UpdateItem, and PartiQL were measured on 17 November 2026. Each request went out twice and got the same answer both times. Before this change, ExtendDB served an index up to 18446744073709551615 and an index with a leading zero.

Closes #1047

Testing done

On the previous revision of the commit:

  • cargo test -p extenddb-core --lib: 1148 passed, 1 ignored. cargo test -p extenddb-engine --lib: 870 passed and 1 failed under load. The failed test is a backup::tests timing test, and it passed when run alone.
  • Against ExtendDB on SQLite, tests/test_list_index_range.py passed 61 tests. Its table holds 60 measured requests on GetItem, UpdateItem, PutItem, DeleteItem, Scan, Query and TransactWriteItems. Together with 64 other wire files on projections, conditions, transactions, expression errors and PartiQL, 4085 tests passed and none failed. Ten tests/python files on items, expressions and Query passed 336.
  • tests/test_dynamodb_attributes_expressions.py and three PartiQL authorization files need admin credentials in the test environment, so their 97 tests did not run locally.

The final revision drops one dead line and five engine test rows that the core and wire tables already cover. On it, the core expression and PartiQL tests passed 561, and the engine expression tests passed 12. cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warnings and cargo fmt --check are clean.

Line counts, with the lines after #[cfg(test)] counted as tests: production +119 -23, tests +426 -0.

Other open PRs:

Not in this PR: ExtendDB's other syntax error texts differ from DynamoDB's in code this PR does not change. Examples are a trailing comma (SET a = :v,), a trailing AND, the near text of an invalid character, and a space inside the brackets (l[01 ], where DynamoDB answers near: "01 ]").

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.

A document path takes a list index from 0 to 2147483647 on Amazon
DynamoDB. ExtendDB served larger indexes up to 18446744073709551615 and
indexes written with a leading zero.

DynamoDB refuses an index above 2147483647 with "List index is not
within the allowable range". The refusal names the first such index of
the expression, as the request wrote it. DynamoDB answers an index of
two or more digits that starts with 0 as a syntax error. A syntax error
anywhere in the expression comes ahead of the range refusal. UpdateItem,
PutItem and DeleteItem put "1 validation error detected: " ahead of
both refusals. TransactWriteItems and the reads do not.

The checks cover the paths of projection, update, condition, filter and
key condition expressions. The PartiQL parser refuses an index above
2147483647 with the same sentence, followed by the number's position.
For SELECT l[2147483648] FROM "t" WHERE pk = 'k' the refusal ends in
"at 1:10:10", the number's line, column and length.

Measured in us-east-1 on 13, 14 and 17 Nov 2026.

Fixes #1047.

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

I think the PartiQL path misses indexes above 18446744073709551615. bracket_step parses the number as usize, and when that fails it falls to refuse_bracket. On SQLite at 5ce57ec, SELECT l[18446744073709551615] FROM "t" WHERE pk = 'k' answers List index is not within the allowable range; index: [18446744073709551615] at 1:10:20, but SELECT l[18446744073709551616] ... and l[99999999999999999999] (select list, WHERE and UPDATE SET) answer Unexpected path component at .... The expression parsers refuse l[99999999999999999999] with the range sentence, and the description says PartiQL refuses any index above 2147483647 the same way. Has the live answer for a 20 digit PartiQL index been measured? If it is the range sentence, an all-digits check before refuse_bracket would cover it, with a row in other_contents_of_brackets_are_refused.

is_list_index_refusal matches any body that starts with Syntax error;, so the count now goes on syntax errors that are not about list indexes. UpdateItem XSET a = :v answered Invalid UpdateExpression: Syntax error; ... on main and now answers 1 validation error detected: Invalid UpdateExpression: Syntax error; .... Same for SET a = :v XSET b = :v. The rows for an unknown character, a bare # and a bare : are measured in main's tests/test_expression_unknown_character.py, but the unknown clause keyword comes from the update parser and I did not find a measurement or a test for it. Was it measured? If not, could the check match only the leading zero error and the character errors, or could you add a measured row for the keyword case? A name that says it covers syntax errors would also help the reader.

Main moved since this branch: #567 added tests/test_expression_unknown_character.py, which marks 9 PutItem, UpdateItem and DeleteItem rows as expected failures because "ExtendDB leaves out the count". With this PR merged into main those rows pass, so the xfail branch in _assert_message and the docstring sentence go stale. Could you merge main and remove both?

SET #missing[2147483648] = :v with no ExpressionAttributeNames used to answer An expression attribute name used in the document path is not defined; attribute name: #missing, and now answers the range refusal. The table measures the undefined value case (= :w). Was the undefined name case measured too?

A question, not a condition: PartiQL SELECT l[01] ... is accepted on main and here. Does DynamoDB accept it in PartiQL?

The branch has a merge conflict with main, so it needs a merge of main before it can land.

I will approve once the PartiQL 20 digit case and the count on the keyword case are settled with a measurement or a fix, and the #567 test file is updated after merging main.

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.

GetItem and UpdateItem accept a list index above 2147483647 or with a leading zero, and DynamoDB refuses it

2 participants