Repository navigation
fix(core): refuse a zero whose exponent is outside the number range - #1572
Open
navareamol wants to merge 12 commits into
Open
navareamol wants to merge 12 commits into
navareamol wants to merge 12 commits into
Conversation
added 12 commits
December 3, 2026 09:54
DynamoDB range checks a zero on its exponent less its fraction digits, as it does any other number: 0E126 is a Number overflow and 0E-131 a Number underflow. ExtendDB range checked only a zero whose exponent did not fit in an i32, so 0e999, 0e126, 0.0e200 and 0e-999 were stored as 0. validate_and_normalize_number now applies the same range rule to a zero with any exponent. A refused zero keeps its raw spelling, so the checks on item, key, Query and expression values refuse it with the existing overflow and underflow messages.
…and in comments The ImportTable row of the differences table said a zero such as 0E126 is imported as 0. It is skipped, as the service skips it. Two code comments said the number check normalizes a zero with any 32-bit exponent to 0. The upgrade entry names the ImportTable change and a zero with many fraction digits.
1.5E-130 - 1.5E-130 gives a zero with 131 fraction digits. The result is checked as a written number, and a zero written that way is now below the range, so UpdateItem answered Number overflow where main stored 0. A zero result is now 0 before the check; other results are checked as before.
…cale" This reverts commit c166ba7.
navareamol
requested review from
LeeroyHannigan,
amrith,
c33howard,
demohan,
eliseong,
hitesh96db,
jcshepherd,
pdf-amzn and
robinnsc
as code owners
December 3, 2026 21:05
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A zero is range checked on its exponent less its fraction digits, as any other number is.
0e999,0e126and0.0e200are refused asNumber overflow, and0e-999asNumber underflow. Those four are the values in the issue. The tests also refuse-0E126(overflow) and0E-131and0.0E-130(underflow). Those three come from the measurements the old code comment cites, not from the issue and not re-measured here.0E125,0.0E126and0E-130are still stored as0.The change is in
validate_and_normalize_number(crates/core/src/validation/number.rs). It range checked a zero only when the exponent did not fit in an i32. It now checks every zero with the rule it already applied to those. A refused zero keeps its raw spelling inAttributeValue, so the checks that already refuse1E126on a path refuse it too. The messages are the existingNumberFaultoverflow and underflow texts.Docs:
docs/differences-from-dynamodb.mdno longer lists the ImportTable zero as a difference. Two code comments that said a zero with any 32-bit exponent is0are corrected (crates/core/src/backup_format/key_order.rs,crates/core/src/expression/update_evaluator.rs).docs/manuals/07-upgrade-manual.mdgets a### v1.2.0:entry.Why
Refs #1526. The issue measured on the live service that these zeros are refused where ExtendDB answered 200. With the fix removed, 119 of the new wire tests fail and 5 core unit tests fail (see Testing done). The issue's table was not re-measured on the live service here.
This is
Refs, notFixes. The issue also namesQueryFilter. The legacyQueryFilter,ScanFilterand ScanExpressionAttributeValuescheck no number on main, for any value (1E126andabcare accepted there, run on this branch), so a zero is not refused there either. #562 covers the Scan values and #618 tracks the rest.Zeros already stored
No released version could store a zero whose exponent fits in an i32 in its raw spelling, so no read, update or restore path needs to accept one. Every request value, PartiQL value, imported row and backup line reaches storage through
AttributeValue's deserializer, and in every tag that deserializer turned such a zero into0:crates/core/src/types/attribute_value.rs:103callsvalidate_and_normalize_number(n).unwrap_or_else(|_| n.to_owned()), andcrates/core/src/validation/number.rs:55returns"0"for any zero. The exponent is read as an i32 (parse::<i32>), so a zero whose exponent does not fit is refused and kept raw. The normalization came in 19b868a, which every tag contains.attribute_value.rs:107andnumber.rs:65.attribute_value.rs:144(:146in v1.1.0) calls the same function, andnumber.rs:159-167(:180-188in v1.1.0) returns"0"for a zero whose exponent fits in an i32 (883f8c7, fix(core): range check number exponents as DynamoDB does #619).crates/engine/src/partiql/write.rs:371andcrates/engine/src/partiql/item_depth.rs:383in v0.1.15 and v1.1.0.serde_json::from_valueintoItem(crates/engine/src/import_export_io.rs:59), and CSV rows hold onlySvalues (:125). Backup data files are read through the deserializer (crates/core/src/backup_format/data_file.rs:1022in v1.1.0), and they are written from stored items. Stream records and index rows are built from stored items.The raw zeros an older release could store are those whose exponent does not fit in an i32. Before #620 (3a5c84b, v0.1.15), BatchWriteItem and TransactWriteItems stored a refused value as written. Main already refuses those zeros, and this change does not alter how they are read. No catalog was scanned. The evidence is the code at each tag.
Side effects
validate_and_normalize_numbersees the new refusal: item values, keys, expression values, PartiQL parameters and literals, ImportTable rows, batch and transaction writes. An ImportTable row holding0E126is now skipped and the import endsFAILED, as the service does. It used to be imported with0.Number underflow. An example is a JavaBigDecimalzero with scale 200 sent as0.followed by 200 zeros. This was run on the branch with0.followed by 140 zeros on PutItem and PartiQL. Whether the live service refuses that input was not measured. The upgrade manual lists it.ExpressionAttributeValues,ScanFilter, legacyQueryFilter), a zero such as0E126used to become0and now keeps its raw spelling. A filtern = :vorn < :vwith it matches nothing, andn <> :v(orNOT (n = :v)) matches every row with a numbern. That is what1E126does on those paths today. A Scan or QueryExclusiveStartKeyholding0E126is compared as written. That was not run.["0E126", "0"]used to be refused as a duplicate, since the reader folded0E126into0(from the code atcrates/core/src/types/attribute_value.rs:246; not run on main). It is now refused asNumber overflow(run on this branch on SQLite, PostgreSQL and Cassandra). The request is invalid either way. The service's answer for it was not measured.check_number(crates/core/src/partiql/number.rs) still accepts a zero at any scale, and its testzero_is_accepted_at_any_scale(crates/core/src/partiql/number/tests.rs:71) pins0e-500. PartiQL refuses these zeros today because its values also pass throughvalidate_and_normalize_number. A future caller ofcheck_numberalone would accept them. fix(core): check a PartiQL number's magnitude before its digit count #1376 also changescheck_number. This PR leaves it as it is.SET #n = :a - :bwith both1.5E-130, orADD n :vof-1.5E-130to a stored1.5E-130, stores0. The result has 131 fraction digits, butBigDecimaldisplays a zero of any scale as0, so the result check reads0and needs no special case. A unit test pins this (a_zero_result_is_zero_whatever_its_scale), and both calls answer 200 with{"N": "0"}on SQLite on this branch. Main computes the result the same way. The live service was not measured.Testing done
The desktop and Mac trees match (
git rev-parse HEAD^{tree}is3913d45a55ca715fb32c6c798af1d2499212b566). The branch has origin/maindb8a90dadmerged in.cargo fmt --checkcargo +1.97.0 clippy -p extenddb-core --all-targets -- -D warnings, and the same for-p extenddb-enginecargo test --no-fail-fast -p extenddb-core -p extenddb-enginecargo test -p extenddb-engine --lib -- --exact <name>, 20 runspytest tests/test_zero_exponent_range.py, three runs on one server, and one more on the final treecargo test --no-fail-fast -p extenddb-core --libEach full engine run had one failing backup test, a different one each time. These were
a_healthy_store_makes_create_backup_store_backed(left: Creating, right: Available, at a load average of about 70),a_second_unknown_outcome_whose_write_landed_is_matched, anda_put_failure_fails_the_row_then_deletes_the_prefix. Each passed 20 of 20 runs alone, on the branch and on main (db8a90dadfor the first two,b6c859508for the third; the first test was run alone only on the branch). The branch changes no file undercrates/engine.The wire file runs each issue value plus
-0E126,0E-131and0.0E-130on these paths:NS,LandM; sort key; condition value.KeyConditions,FilterExpressionvalue.That makes 7 values times 17 test functions, 119 tests. One is skipped (the
-0E126PartiQL literal, which PartiQL refuses with its own negative zero text), so 118 run. The file also checks that0E125,0.0E126,0E-130and0are stored as0(4 tests), that a refused zero in a batch writes nothing, and the number set above. That gives 124 passed and 1 skipped.The control mutation, applied on the clean committed tree and reverted with
git checkout --, withgit status --shortempty afterwards:With the mutation, five core unit tests fail:
zero_with_exponent_inside_i32_is_range_checkedzero_with_exponent_outside_i32_is_range_checkedexponents_at_the_ends_of_i32_classify_the_magnitudedoc_examples_normalize_as_statedimport_row_accepts_what_the_service_importsThe 119 failing wire tests are the 118 refusal tests that run, plus
test_a_refused_zero_writes_nothing. The 5 that still pass are the 4 in-range zeros and the number set test, which gets a duplicate refusal instead of the overflow and only checks for aValidationException. So the number set test detects no change. It records the answer.Rerun on SQLite: build with
cargo build -p extenddb --no-default-features --features sqlite,extenddb init --backend sqlite,extenddb serve, provision credentials withdevtools/provision-test-credentials, thenpytest tests/test_zero_exponent_range.py. PostgreSQL uses the default build and Cassandra--features cassandra.Not run: MongoDB (outside 1.0), the MSRV build, and
cargo check --target x86_64-pc-windows-msvc(nocfg(unix)item moved). The wire file was not run against main. The control stands in for it.Overlap with open PRs, from
git merge-treeagainst this branch:crates/core/src/validation/number.rsamong them. Thenumber.rsconflict is in theNUMBER_SET_DUPLICATESdoc comment, not in the zero branch. fix(scan): report every Limit, Segment and TotalSegments range fault in the service's two forms #850 conflicts with origin/main in the same 12 files.Open question
The issue gives "the overflow text" and "the underflow text" for zeros, not the messages. This change reuses the repo's existing measured texts, and each operation's prefix comes from its existing wrapper. The wire tests match only the words
Number overflowandNumber underflow. Has anyone measured the exact text and prefix the live service gives for a zero on each operation, and its answer for0.followed by 140 zeros?