Repository navigation
fix(server): read a number written with leading zeros in a request body - #1344
LeeroyHannigan wants to merge 7 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
-
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.rsandcrates/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 inlib.rs(main'stest_contextmodule and the branch's widerpub use) and the branch side of the two doc comments. That tree builds,test_syntax_fault_message.pyandtest_request_nesting_depth.pypass 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? -
Some numbers in the description come from older revisions. It says "production +82 -18, tests +79 -39" at 693b815. Splitting
request_parse.rsat#[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 tickscargo 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.
On |
|
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 I will approve once the stack is rebased onto main and CI has run on the merged tree. |
Changes since the last review
request_parse.rsand oftests/test_syntax_fault_message.pyapart. The section on conflicts gives the trial merge withmainat c057660. "Not in this PR" now has theLimitof-0and-00, measured on DynamoDB on 3 December 2026.Merge fix/1195-syntax-fault-message into fix/1257-leading-zero-numbers. It merges fix(server): send no message for a body with a JSON syntax fault #1261 at 600726b, which carries fix(server): parse request bodies nested to the depth the service validates #807 at 71b3e1b. fix(server): parse request bodies nested to the depth the service validates #807's 71b3e1b adds rows at the edges of the syntax check's looser rules. At 63 and at 20000 wrappers,1+,1e+5,1.eE-+and\uggggreach authentication.+1,.5,\u000/and\u000hget a refusal before it. One file conflicted:crates/server/src/request_parse.rs, ina_body_with_a_syntax_fault_is_refused_with_no_message. The eight refused rows go into this PR's table withNone, and its comment names them with their measurement. None of them has a number with a leading zero, soread_jsonrefuses each after one read.tests/test_request_nesting_depth.pyauto-merged. At 693b815,cargo fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warningsare clean. So iscargo +1.91.1 check -p extenddb-server --all-targets. The 11request_parseunit tests pass. Three changes to the check each fail a new row, as on fix(server): send no message for a body with a JSON syntax fault #1261.tests/test_request_nesting_depth.py(105) andtests/test_syntax_fault_message.py(27) pass 132 tests against SQLite. The clippy step ofwasm.ymlis clean, run locally with a stand-in C compiler because clippy does not link.pytest --collect-onlycollectstests/(6792) andtests/python(672) with no error.Merge fix/1195-syntax-fault-message into fix/1257-leading-zero-numbers. It merges fix(server): send no message for a body with a JSON syntax fault #1261 at 7d7a089, which carries fix(server): parse request bodies nested to the depth the service validates #807 at 027483d and two commits of fix(server): send no message for a body with a JSON syntax fault #1261. fix(server): parse request bodies nested to the depth the service validates #807's 027483d changes one sentence of the WebAssembly adapter's module doc. After fix(server): send no message for a body with a JSON syntax fault #1261's two commits, the helper_is_messageless_serialization_erroroftests/test_request_nesting_depth.pycompares the whole error document. REQ-ERR-002 indocs/design/01-requirements.mdnow says that aSerializationExceptionfor a body that does not parse has no message field. No file conflicted, and none of these commits changes a file of this PR. This PR's change over fix(server): send no message for a body with a JSON syntax fault #1261 is byte for byte its change before the merge. At 7ad2a44,cargo fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warningsare clean. The 11request_parseunit tests pass.tests/test_request_nesting_depth.pyandtests/test_syntax_fault_message.pypass 100 tests against SQLite. The clippy step ofwasm.ymlis clean, run locally with a stand-in C compiler because clippy does not link.pytest --collect-onlycollectstests/(6760) andtests/python(672) with no error.Merge fix/1195-syntax-fault-message into fix/1257-leading-zero-numbers. It merges fix(server): send no message for a body with a JSON syntax fault #1261 at 654fef3, which carries fix(server): parse request bodies nested to the depth the service validates #807 at 1a9efd7 and main at b0d1c64: test(storage-mongodb): end the killed holder's lease by data, not by waiting #1280, feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 and UpdateExpression ADD creates no missing map on its path #596. fix(server): parse request bodies nested to the depth the service validates #807's 1a9efd7 makes the handler callextenddb_engine::check_operationandwith_body(input).admit()around the server's parse. fix(server): send no message for a body with a JSON syntax fault #1261's merge edits the README item on the PartiQL operations. The item now says that a server answers a body that does not parse with no message. No file conflicted, and none of these commits changes a file of this PR. This PR's change over fix(server): send no message for a body with a JSON syntax fault #1261 is byte for byte its change before the merge. At 61eee55,cargo fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warningsare clean. The 11request_parseunit tests pass.tests/test_request_nesting_depth.pyandtests/test_syntax_fault_message.pypass 100 tests against SQLite. The clippy step ofwasm.ymlis clean, run locally with a stand-in C compiler because clippy does not link.pytest --collect-onlycollectstests/(6760) andtests/python(672) with no error.Merge fix/1195-syntax-fault-message into fix/1257-leading-zero-numbers. It merges fix(server): send no message for a body with a JSON syntax fault #1261 at 0986467, which carries fix(server): parse request bodies nested to the depth the service validates #807 at b9baaf5 and main at 018715e: fix(sqlite): render the stream retention cutoff in the created_at column shape #503, fix(engine): compare the Return fields on a TransactWriteItems token replay #526, fix: match data relations by catalog id in catalog-check, so --fix keeps live tables #690, fix(scan): drop the FilterExpression suffix from the values message #765 and fix(server): send Message on the two errors the service sends it on #774. No file conflicted, and this PR's change over fix(server): send no message for a body with a JSON syntax fault #1261 is byte for byte its change before the merge. fix(server): send Message on the two errors the service sends it on #774 changescrates/server/src/response.rs, which renders the refusals these tests assert. ASerializationExceptionkeeps themessagekey, and a refusal with an empty message still has no message key. At 54ed1f2,cargo fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warningsare clean. The 11request_parseunit tests pass.tests/test_request_nesting_depth.pyandtests/test_syntax_fault_message.pypass 100 tests against SQLite.pytest --collect-onlycollectstests/(6737) andtests/python(672) with no error.docs(server): say that the parse reads a number with leading zeros. The security manual's paragraph on the syntax check, from fix(server): parse request bodies nested to the depth the service validates #807, said that only the parse after authentication refuses the forms the check passes. It now says that the parse reads a number written with leading zeros, such as01, as the decimal number its digits spell. The parse refuses the other forms.Merge fix/1195-syntax-fault-message into fix/1257-leading-zero-numbers. It merges fix(server): send no message for a body with a JSON syntax fault #1261 at 748d21e, which carries fix(server): parse request bodies nested to the depth the service validates #807's fix round (the syntax scanrequest_syntax::skip_value) and main at 6aef346. Two hunks ofcrates/server/src/request_parse.rsconflicted.check_request_syntaxkeeps fix(server): send no message for a body with a JSON syntax fault #1261's one-line call ofskip_value. This PR'sread_jsonwrap of the check goes, becauseskip_valuereads a number with leading zeros as sent. The unit test keeps this PR's rows, which name the body the server reads, and gains fix(server): parse request bodies nested to the depth the service validates #807's seven leaf faults as refused rows. The merge also makeswithout_leading_zeroscallrequest_syntax::number_byteinstead of spelling the same six byte classes again. At 00ccd3b,cargo fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warningsare clean. The 11request_parseunit tests pass.tests/test_request_nesting_depth.pyandtests/test_syntax_fault_message.pypass 100 tests against SQLite.What
The server now reads a number written with leading zeros in a request body, such as
01,-010or00.5. It reads the number as the decimal number its digits spell, as DynamoDB does. Before this change, such a body got aSerializationExceptionwith no message, because serde_json refuses a leading zero.The changes are in
crates/server/src/request_parse.rs:read_jsoncallswithout_leading_zeros, which removes the leading zeros of each number outside a string. Thenread_jsonreads the new body once more.parse_request_value) callsread_json. The syntax check before authentication (check_request_syntax) is fix(server): parse request bodies nested to the depth the service validates #807'sskip_value, which reads a number with leading zeros as sent. So the two accept such a body alike.without_leading_zerosmakes 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 ofrequest_syntax::number_byte.parse_request_valuechecks first, also applies to the second read.nesting_depthkept inline is now the structStringScan.nesting_depthandwithout_leading_zerosboth use it.StringScanstays besiderequest_syntax's string skip.StringScantells two byte-by-byte passes whether each byte is outside every string literal, with no validation.Scan::skip_stringmoves 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
SerializationExceptionwith 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.
ResourceNotFoundException.SerializationExceptionwith no message.ValidationException.xthat is not in the model, of value01,00,-01,01.5,00.5,01e1,0001or-00xof value[01, 02]or{"y": 01}, or with"x": 01beforeTableNameLimit01Limit00,-01or-010Value '0',Value '-1'orValue '-10'atlimitSegment0andTotalSegments01000001Value '1000001'attotalSegmentsSegment01andTotalSegments01Segment: 1 is not less than TotalSegments: 1Segment010andTotalSegments0Value '0'attotalSegmentsReadCapacityUnits00andWriteCapacityUnits01Value '0'atprovisionedThroughput.readCapacityUnitsExtendDB'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
-010as -10.The rows where DynamoDB answers VE do not match on a missing table. ExtendDB's Scan finds the table before it checks
Limit,SegmentandTotalSegments, 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
Segment010row is different: it gets ExtendDB's sentenceThe parameter TotalSegments should be greater than or equal to 1(#563). The UpdateTable row getsOne 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
run-testsjobs, on stable and on 1.91.1, rancargo test --locked --workspace --exclude extenddb-backup-storeandcargo 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 warningsandcargo +1.97.0 fmt --all -- --checkare clean at b092570 and at 00ccd3b.request_parse.rsfrom 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_messagefails at its first row with a leading zero.Limit01returned 1 item. An UpdateTable with01and02set the capacity to 1 and 2.SelectCOUNTand aLimitof010or0010counted 10 items."x": 01at the top level stored the item, and GetItem returned it as for the body withoutx. Strings such as00,a"01and-01kept their bytes.request_parse.rsof 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.pyandtests/test_request_nesting_depth.pypassed 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.01at the leaf of a body nested 126, 127, 128, 200 or 5200 levels, each request got the answer of the same body with1. At 5201 levels, a signed request gets SE from the depth ceiling. An unsigned one getsMissingAuthenticationTokenat every depth.The runs above used the previous revision of the commit. The last revision changes one doc comment, and
cargo fmt --checkis 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:
1, with no leading zero01as the first number01as the last numberThe answer is
MissingAuthenticationTokenwhere 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)]incrates/server/src/request_parse.rs, and +15 -1 are intests/test_syntax_fault_message.py. One line of the security manual changes.git merge-treeof 693b815 shows no conflict with #1265 at 53d0c75, the only open PR outside this stack that changesrequest_parse.rsortests/test_syntax_fault_message.py. The branch containsmainat b0d1c64. The merged tree with #1265 was not built. 28 open PRs outside #807, #1261, #1265, #1344 and #1372 changedocs/manuals/10-security-model.md. Of these, only #140 conflicts with this branch in that file, and it has the same four conflict hunks withmain.With
mainat c057660 (3 December 2026),git merge-treeof 693b815 reports conflicts inREADME.md,crates/engine/src/lib.rsandcrates/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,
Limit00gets the text form with no value,Value at 'Limit', where DynamoDB givesValue '0' at 'limit'(#563). Before this PR, the same body gets SE.Not in this PR:
1.,1eor-(A request body with a number form that JSON does not allow, such as 1. or -, gets SerializationException, where DynamoDB reads several of them #1343).Limit.01.5and00.0now get the answer that1.5and0.0get, aSerializationExceptionwith serde_json's text. fix(scan): report every Limit, Segment and TotalSegments range fault in the service's two forms #850 reads a fractional ScanLimitas DynamoDB does, and Query: an empty AttributesToGet, a fractional Limit, a value nested 32 levels deep and a malformed number in ExclusiveStartKey answer differently from the service #720 covers Query.Limitof0(Scan range constraints: the service aggregates Limit, Segment and TotalSegments faults and uses two text forms by the value's size #563).Limitof-0. DynamoDB reads-0and-00as 0 and answers1 validation error detected: Value '0' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1(3 December 2026, a table that does not exist, each request twice). serde_json reads-0as a float. So ExtendDB answers-0with aSerializationExceptionwith the messageStart of structure or map found where not expected: invalid type: floating point `-0.0`, expected i64, on fix(server): send no message for a body with a JSON syntax fault #1261 and with this PR. This PR rewrites-00as-0, so-00now gets that answer too, where fix(server): send no message for a body with a JSON syntax fault #1261 gave aSerializationExceptionwith no message. Scan range constraints: the service aggregates Limit, Segment and TotalSegments faults and uses two text forms by the value's size #563 records the-0row, and fix(scan): report every Limit, Segment and TotalSegments range fault in the service's two forms #850 reads aLimitof-0as 0.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 body with a number written with leading zeros, such as
01,-010or00.5, now gets the answer that the same body gets with the plain number. Before this change, it got aSerializationExceptionwith no message. For example, on a table with two items, a Scan withLimit01now returns 1 item. An UpdateTable withReadCapacityUnits00now gets theValidationExceptionfor a capacity below 1. A fractional number with leading zeros, such as aLimitof01.5, gets serde_json'sSerializationExceptiontext, as1.5does. ALimitof-00gets the text that-0gets.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.