Skip to content

fix(server): read a number written with leading zeros in a request body - #1344

Open
LeeroyHannigan wants to merge 7 commits into
fix/1195-syntax-fault-messagefrom
fix/1257-leading-zero-numbers
Open

LeeroyHannigan wants to merge 7 commits into
fix/1195-syntax-fault-messagefrom
fix/1257-leading-zero-numbers

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

The server now reads a number written with leading zeros in a request body, such as 01, -010 or 00.5. It reads the number as the decimal number its digits spell, as DynamoDB does. Before this change, such a body got a SerializationException with no message, because serde_json refuses a leading zero.

The changes are in crates/server/src/request_parse.rs:

  • When serde_json refuses a body, the new function read_json calls without_leading_zeros, which removes the leading zeros of each number outside a string. Then read_json reads the new body once more.
  • The parse (parse_request_value) calls read_json. The syntax check before authentication (check_request_syntax) is fix(server): parse request bodies nested to the depth the service validates #807's skip_value, which reads a number with leading zeros as sent. So the two accept such a body alike.
  • without_leading_zeros makes one pass over the body and does not recurse. It keeps the minus sign, and it keeps one zero before a fraction, an exponent or the end of the number. When it removes no zero, it returns nothing, and the body is not read again. Its number bytes are those of request_syntax::number_byte.
  • The bytes of strings and the nesting do not change. So the depth ceiling, which parse_request_value checks first, also applies to the second read.
  • A body that serde_json accepts gets one read, as before, with no copy.
  • The string and escape state that nesting_depth kept inline is now the struct StringScan. nesting_depth and without_leading_zeros both use it. StringScan stays beside request_syntax's string skip. StringScan tells two byte-by-byte passes whether each byte is outside every string literal, with no validation. Scan::skip_string moves a cursor past one literal and refuses the escapes and control bytes the service refuses. Neither can do the other's job without a new mode.

The change adds no check and no error text. A body that serde_json still refuses after the second read gets the SerializationException with no message, as before.

The security manual's paragraph on the syntax check (docs/manuals/10-security-model.md) now says that the parse after authentication reads a number written with leading zeros.

The WebAssembly build parses a body with serde_json's defaults, so it still refuses such a number (#1471).

The base of this PR is #1261.

Why

These are DynamoDB's answers, measured in us-east-1 on 21 November 2026 with signed requests. Each request went out twice and got the same answer both times. Every request names a table that does not exist.

  • RNF is ResourceNotFoundException.
  • SE is SerializationException with no message.
  • VE is ValidationException.
Request DynamoDB ExtendDB on #1261 ExtendDB with this PR
DescribeTable with a member x that is not in the model, of value 01, 00, -01, 01.5, 00.5, 01e1, 0001 or -00 RNF SE RNF
DescribeTable with x of value [01, 02] or {"y": 01}, or with "x": 01 before TableName RNF SE RNF
Scan, Limit 01 RNF SE RNF
Scan, Limit 00, -01 or -010 VE, Value '0', Value '-1' or Value '-10' at limit SE RNF
Scan, Segment 0 and TotalSegments 01000001 VE, Value '1000001' at totalSegments SE RNF
Scan, Segment 01 and TotalSegments 01 VE, Segment: 1 is not less than TotalSegments: 1 SE RNF
Scan, Segment 010 and TotalSegments 0 VE, Value '0' at totalSegments SE RNF
UpdateTable, ReadCapacityUnits 00 and WriteCapacityUnits 01 VE, Value '0' at provisionedThroughput.readCapacityUnits SE VE, with ExtendDB's capacity sentence

ExtendDB's RNF text for DescribeTable leaves out the table name (#1055).

The values in DynamoDB's VE texts show that it reads the digits as decimal. For example, it reads -010 as -10.

The rows where DynamoDB answers VE do not match on a missing table. ExtendDB's Scan finds the table before it checks Limit, Segment and TotalSegments, but DynamoDB checks these ranges first. #850 moves these checks before the table lookup, for Scan and for Query.

On a table that exists, this PR answers each of these Scan rows with the text DynamoDB gave on the missing table. The Segment 010 row is different: it gets ExtendDB's sentence The parameter TotalSegments should be greater than or equal to 1 (#563). The UpdateTable row gets One or more parameter values were invalid: ReadCapacityUnits and WriteCapacityUnits must each be at least 1 (#1147). ExtendDB gives the same two texts to these bodies with the zeros removed.

Fixes #1257

Testing done

  • CI's Test workflow passed at 693b815 (run 45570674635, 25 November 2026). Its run-tests jobs, on stable and on 1.91.1, ran cargo test --locked --workspace --exclude extenddb-backup-store and cargo test --locked -p extenddb-backup-store. In each job, the server crate's unit tests gave 530 passed and 0 failed.
  • cargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean at b092570 and at 00ccd3b.
  • With the production code of request_parse.rs from fix(server): send no message for a body with a JSON syntax fault #1261 and the tests of this PR, a_body_with_a_syntax_fault_is_refused_with_no_message fails at its first row with a leading zero.
  • The rows of the table went twice to a SQLite server built from this change, and twice to one built from fix(server): send no message for a body with a JSON syntax fault #1261's head. Each server gave the same answer to both sends.
  • On a table with two items, each Scan row and the UpdateTable row got the answer that the same body gets with the zeros removed. A Scan with Limit 01 returned 1 item. An UpdateTable with 01 and 02 set the capacity to 1 and 2.
  • On a table with 12 items, a Scan with Select COUNT and a Limit of 010 or 0010 counted 10 items.
  • A PutItem with "x": 01 at the top level stored the item, and GetItem returned it as for the body without x. Strings such as 00, a"01 and -01 kept their bytes.
  • A test program compiled the request_parse.rs of both trees and sent 4608 bodies through the parse and the syntax check. The bodies included named cases and 4000 random bodies with leading zeros, strings with escapes, nesting and syntax faults. This PR gave each body the answer that fix(server): send no message for a body with a JSON syntax fault #1261 gives to the same body with its leading zeros removed. The parse read a body exactly when a reference reader that accepts leading zeros read it, and to the same value.
  • tests/test_syntax_fault_message.py and tests/test_request_nesting_depth.py passed against this change's server at b092570, 54 tests. Against fix(server): send no message for a body with a JSON syntax fault #1261's server, the 12 new rows fail with SE.
  • With 01 at the leaf of a body nested 126, 127, 128, 200 or 5200 levels, each request got the answer of the same body with 1. At 5201 levels, a signed request gets SE from the depth ceiling. An unsigned one gets MissingAuthenticationToken at every depth.

The runs above used the previous revision of the commit. The last revision changes one doc comment, and cargo fmt --check is clean on it.

Cost, with unsigned 16 MiB bodies sent three times each over TLS to a server on 127.0.0.1 on this host:

Body #1261 This PR
A list of 1, with no leading zero 391 to 426 ms 374 to 450 ms
01 as the first number 47 to 52 ms, SE 428 to 445 ms
01 as the last number 378 to 387 ms, SE 776 to 898 ms

The answer is MissingAuthenticationToken where the table shows no SE.

A refused body with a leading zero costs one more pass over the bytes, one copy and one more serde_json read. After the 16 MiB bodies with leading zeros, the peak resident memory of the server was 344 to 395 MiB. On #1261 it was at most 358 MiB.

The test program also timed the depth scan on 16 MiB bodies, best of 11 to 15 runs. For a body of numbers, it took 13.7 ms against 9.1 ms on #1261. For an item of small attributes, it took 13.8 ms against 15.3 ms.

Line counts of this PR's own change at 693b815, against #1261 at 600726b: production +82 -18, and 21 of the added production lines are comments. The tests are +79 -39. Of these, +64 -38 come after #[cfg(test)] in crates/server/src/request_parse.rs, and +15 -1 are in tests/test_syntax_fault_message.py. One line of the security manual changes.

git merge-tree of 693b815 shows no conflict with #1265 at 53d0c75, the only open PR outside this stack that changes request_parse.rs or tests/test_syntax_fault_message.py. The branch contains main at b0d1c64. The merged tree with #1265 was not built. 28 open PRs outside #807, #1261, #1265, #1344 and #1372 change docs/manuals/10-security-model.md. Of these, only #140 conflicts with this branch in that file, and it has the same four conflict hunks with main.

With main at c057660 (3 December 2026), git merge-tree of 693b815 reports conflicts in README.md, crates/engine/src/lib.rs and crates/wasm-adapter/src/runtime.rs. #1261 at 600726b and #807 at 71b3e1b have the same three conflicts. This PR changes none of the three files.

With #850, a number written with leading zeros reaches the Scan checks as a plain integer. So after both merge, Limit 00 gets the text form with no value, Value at 'Limit', where DynamoDB gives Value '0' at 'limit' (#563). Before this PR, the same body gets SE.

Not in this PR:

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

Breaking changes

A body with a number written with leading zeros, such as 01, -010 or 00.5, now gets the answer that the same body gets with the plain number. Before this change, it got a SerializationException with no message. For example, on a table with two items, a Scan with Limit 01 now returns 1 item. An UpdateTable with ReadCapacityUnits 00 now gets the ValidationException for a capacity below 1. A fractional number with leading zeros, such as a Limit of 01.5, gets serde_json's SerializationException text, as 1.5 does. A Limit of -00 gets the text that -0 gets.


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 a request body with a number written with a leading
zero, such as 01, with a SerializationException, because serde_json
refuses such a number. DynamoDB reads the number as the decimal number
its digits spell, in any position of the body. It reads 01, 00, -01,
01.5, 00.5, 01e1, 0001 and -00 in a member that is not in its model.
It reads a Scan Limit of -010 as -10 and a TotalSegments of 01000001 as
1000001. Measured in us-east-1 on 21 Nov 2026.

When serde_json refuses a body, the parse and the syntax check before
authentication now remove the leading zeros of each number outside a
string. Then they read the body again. The pass does not recurse. It
keeps the minus sign, and it keeps one zero before a fraction, an
exponent or the end of the number. The bytes of strings and the nesting
do not change, so the bound of the depth scan applies to the new body.
The server reads a body that serde_json accepts in one pass, as before.
The depth scan and the new pass use one string tracker.

Fixes #1257.
Merges 748d21e of fix/1195-syntax-fault-message. That brings in
fix/request-nesting-depth at 4c2995c and the merge commit of that
branch. The 4c2995c head holds the syntax scan with the service's
grammar in request_syntax.rs and the merges of main at 44cd436 and
6aef346.

Conflicts and their resolution, both in crates/server/src/request_parse.rs:

- check_request_syntax: this branch wrapped the serde_json skip in
  read_json so a number with leading zeros passes the check. The other
  branch replaced the skip with request_syntax::skip_value. Its number
  lexeme is `-` or a digit and then any run of number bytes, so `01`
  passes it as sent. Kept: the other branch's one-line call and doc
  comment. The wrap and the sentence about leading zeros go.
- a_body_with_a_syntax_fault_is_refused_with_no_message: this branch
  gave each row the body that spells the value the server reads, with
  the leading zero rows. The other branch added seven leaf faults as
  rows the server refuses. Kept: this branch's shape, with the seven
  leaf faults as rows that read as None, and one comment.

without_leading_zeros now calls request_syntax::number_byte for its
number bytes instead of spelling the same six byte classes again.

StringScan stays beside request_syntax's string skip. StringScan tells
two byte-by-byte passes (nesting_depth and without_leading_zeros)
whether each byte is outside every string literal, with no validation.
Scan::skip_string moves a cursor past one literal and refuses the
escapes and control bytes the service refuses. Neither can do the
other's job without a new mode.
The security manual's paragraph on the syntax check, from
fix/request-nesting-depth, said that only the parse after authentication
refuses the forms the check passes. On this branch the parse reads a
number written with leading zeros as the decimal number its digits
spell, and refuses the other forms. The sentence now says so.
Merges 0986467 of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at b9baaf5. That commit merges main at
018715e, five commits past 6aef346:

- #503: the stream retention cutoff shape on SQLite
- #526: the Return fields on a TransactWriteItems token replay
- #690: catalog-check matches data relations by catalog id
- #765: the FilterExpression suffix in the values message
- #774: the Message key on two errors

No conflicts. None of the five changes a file of this branch. #774
changes crates/server/src/response.rs, which renders the refusals that
this branch's tests assert. SerializationException keeps the message
key, and a refusal with an empty message still has no message key.
Merges 654fef3 of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at 1a9efd7. That brings main at b0d1c64
(#1280, #1009 and #596). It also brings the commit that makes the
handler call extenddb_engine::check_operation and
with_body(input).admit() around the server's parse. The README item on
the PartiQL operations now says that a server answers a body that does
not parse with no message.

No conflicts. None of these commits changes a file of this branch.
Merges 7d7a089 of fix/1195-syntax-fault-message. That brings three
commits:

- its merge of fix/request-nesting-depth at 027483d, which changes one
  sentence of the WebAssembly adapter's module doc
- 3f5ccff, after which the helper _is_messageless_serialization_error
  of tests/test_request_nesting_depth.py compares the whole error
  document
- 7d7a089, after which REQ-ERR-002 in docs/design/01-requirements.md
  says that a SerializationException for a body that does not parse has
  no message field

No conflicts. None of these commits changes a file of this branch.
Merges 600726b of fix/1195-syntax-fault-message, its merge of
fix/request-nesting-depth at 71b3e1b. That brings the rows at the
edges of the syntax check's looser rules. At 63 and at 20000 wrappers,
the numbers 1+, 1e+5 and 1.eE-+ and the escape \ugggg reach
authentication. The numbers +1 and .5 and the escapes \u000/ and \u000h
get a refusal before it.

One conflict, in crates/server/src/request_parse.rs. This branch's
a_body_with_a_syntax_fault_is_refused_with_no_message has a row type of
its own: the body that spells the value the server reads, or None. The
eight refused rows go into this table with None. Its comment names them
with their measurement. None of them has a number with a leading zero,
so the parse refuses each on its first pass, with no message.

tests/test_request_nesting_depth.py auto-merged with the other branch's
rows. Each refused row there expects a SerializationException with no
message field.

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

  1. The head does not merge cleanly with current main. A trial merge of 693b815 with main at aff626e conflicts in README.md, crates/engine/src/lib.rs and crates/wasm-adapter/src/runtime.rs. This PR changes none of them, and #1261 at 600726b has the same three conflicts with main, so they come from main moving under the stack. I kept both lines in lib.rs (main's test_context module and the branch's wider pub use) and the branch side of the two doc comments. That tree builds, test_syntax_fault_message.py and test_request_nesting_depth.py pass 132 of 132 on SQLite, and my leading zero probes answer as on the head. CI ran against the base branch, not a tree with main in it. Could the stack be brought up to date with main when #807 and #1261 move, so CI runs on the merged code?

  2. Some numbers in the description come from older revisions. It says "production +82 -18, tests +79 -39" at 693b815. Splitting request_parse.rs at #[cfg(test)] on the base and the head, I count production +82 -18 and tests +64 -38 (the file's numstat is +146 -56). Testing done gives 506 passed for the server crate tests at b092570; at the head that run gives 530 passed here. The checklist ticks cargo test --workspace, and I could not find a workspace run described for any revision. I think the numbers should be updated to the head, or the box unticked.

Not a condition: "Limit": -00 now gets the SerializationException with serde's text about the floating point -0.0, because serde_json reads -0 as a float. A plain -0 gets the same answer before this PR, so the PR does not cause it. Has anyone sent a Limit of -0 or -00 to the service? If it reads them as 0, that could be a separate issue.

I will approve once the description numbers match the head.

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

  1. At main c057660 (3 December 2026), git merge-tree gives the same three conflicting files for this head 693b815, for fix(server): send no message for a body with a JSON syntax fault #1261 at 600726b and for fix(server): parse request bodies nested to the depth the service validates #807 at 71b3e1b: README.md, crates/engine/src/lib.rs and crates/wasm-adapter/src/runtime.rs. This PR changes none of them. The stack takes main at fix(server): parse request bodies nested to the depth the service validates #807 first. Then each branch merges its parent's new head, so CI runs on the merged trees.

  2. I get your counts for request_parse.rs. Against fix(server): send no message for a body with a JSON syntax fault #1261 at 600726b, production is +82 -18, and the lines after #[cfg(test)] are +64 -38. The description's tests +79 -39 also counted tests/test_syntax_fault_message.py, +15 -1, and did not say so. It now gives both parts. For the workspace run, CI's Test workflow passed at 693b815, in run 45570674635 on 25 November 2026. Its run-tests jobs, on stable and on 1.91.1, ran cargo test --locked --workspace --exclude extenddb-backup-store and cargo test --locked -p extenddb-backup-store with no failed test. In each job, the server crate's unit tests gave 530 passed, the count you got. Testing done now names that run, in place of the 506 at b092570.

On -0 and -00: on 3 December 2026 I sent a signed Scan for a table that does not exist to DynamoDB, each body twice. "Limit": 0 got 1 validation error detected: Value at 'Limit' failed to satisfy constraint: Member must have value greater than or equal to 1. "Limit": -0 and "Limit": -00 both got 1 validation error detected: Value '0' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1. So the service reads both as 0. On SQLite, #1372's head, which holds this PR's change, answers both with the SerializationException about -0.0. #1261's head answers -0 the same way and -00 with no message. #563 already records the -0 row, and #850 reads a Limit of -0 as 0, so I did not open an issue. The description now lists this under "Not in this PR".

@navareamol

Copy link
Copy Markdown
Collaborator

The description numbers now match what I count. Splitting request_parse.rs at the test module I get production +82 -18 and tests +64 -38, plus +15 -1 in tests/test_syntax_fault_message.py, which is your +79 -39. Run 45570674635 at 693b815 ran the workspace commands on stable and 1.91.1 and I read 530 passed and no failed test in both jobs, so the checklist box has a run behind it.

The three conflicting files at main c057660 are the same ones I get, and none of them is changed by this PR. The stack order you describe (main into #807 first, then each branch merges its parent) is what I would expect.

On -0 and -00: I read your measurement as the answer to my question, and I have not repeated it against the service. Against the code, -0 is read by serde_json as a float, so both #1261 and this head answer it with the SerializationException about floating point -0.0, and this PR turns the message free answer for -00 into that same answer. That is a different wrong answer for -00, and it is listed under "Not in this PR", so I am not asking for a change here.

I will approve once the stack is rebased onto main and CI has run on the merged tree.

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