Skip to content

fix(core): range check number exponents as DynamoDB does - #619

Merged
eliseong merged 5 commits into
mainfrom
fix/616-number-exponent-overflow
Nov 10, 2026
Merged

eliseong merged 5 commits into
mainfrom
fix/616-number-exponent-overflow

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What

#394 (34aa2df, backup format v1) moved the three exponent sums in validate_and_normalize_number to saturating i64 arithmetic, which fixed the overflow #616 reports. Main 817b240 answers the first three rows of the first table below as DynamoDB does. On abf8082 a debug build panicked on the first and third. Main still parses the exponent as an i32, so an exponent between the i32 and i64 limits is refused as cannot be converted to a numeric value, where DynamoDB answers Number overflow or Number underflow. This PR carries the i64 exponent, the zero check that goes with it, and DynamoDB's answers at both ends of the i64 range.

In crates/core/src/validation/number.rs:

  • The exponent is parsed as an i64, as DynamoDB reads it, and the sums are done in i128, where none of them can overflow. This replaces feat(core): backup format v1: streaming data files, sidecar manifest hash, typed backup ARN [backup/restore 3/4] #394's saturating i64 sums and its len_i64 helper with digit_count and check_magnitude. 1E2147483648 is now Number overflow and 1E-2147483649 Number underflow. Main answers cannot be converted for both. 1E9223372036854775808 is still cannot be converted, as on DynamoDB.
  • A zero whose exponent does not fit in an i32 is range checked (0E2147483648 is Number overflow). Main refuses those zeros as cannot be converted, so the set of refused inputs does not change.
  • DynamoDB computes the exponent of a number's normalized form, the order of magnitude plus one, in 64 bits. A new helper, normalized_exponent_exceeds_i64, reports when that sum leaves the i64 range. For a zero, the sum leaves the range only when the exponent is exactly 9223372036854775807 with no fraction digit. The sum then wraps to a negative exponent, and the answer is Number underflow. A fraction digit lowers the exponent before the sum, so 0.0E9223372036854775807 stays Number overflow. For a nonzero value, the order of magnitude is now computed before the digit count. A sum above the range then answers Number overflow, and the digit count does not run.
  • The same rule applies at the small side of the range. A nonzero value whose normalized exponent is below the i64 minimum answers Number underflow, and the digit count does not run. The helper normalized_exponent_is_below_i64 reports that case, and its check runs after the overflow check and before the digit count. A nonzero value with at most 38 digits and such an exponent was already an underflow through check_magnitude. Relative to 39a41fb, only nonzero values with more than 38 digits get a different answer. The zero path does not change.
  • A zero whose exponent fits in an i32 is still accepted as 0. DynamoDB refuses 0E126 and 0.0E-130. But a zero refused here keeps its raw spelling in AttributeValue. Afterwards, only the PutItem item and UpdateItem's ExpressionAttributeValues and AttributeUpdates go through the number check. BatchWriteItem, TransactWriteItems, UpdateItem's key and the other operations would then store and look up 0E126 as a key separate from 0. BatchWriteItem, TransactWriteItems and other operations store N values that fail number validation as written #618 covers that validation gap and the zero check together. The unit test zero_with_i32_exponent_stays_accepted_until_618 marks the place to change.

The PR keeps the test #394 added in number.rs, exponents_at_the_ends_of_i32_classify_the_magnitude.

The branch merges main at 887b6e2 (e80d018). Main had not changed number.rs or tests/rust/src/number_validation.rs since the branch was cut, and the merge has no conflicting file.

Measured

The DynamoDB column is PutItem with a non-key N attribute in us-east-1. Each value was sent twice, with the same answer both times. In the first table, the four rows above the last one were measured on 2026-11-09, and the last row on 2026-11-10. The other rows were measured on 2026-10-27. The ExtendDB columns are PutItem with the same attribute against dev-mode SQLite servers. Main 817b240 and the branch head of that day ran on 2026-10-30. For the last five rows, this branch ran at 39a41fb on 2026-11-10.

Value DynamoDB main 817b240 this branch
10E2147483647, 12E2147483647, 100E2147483647, -10E2147483647 Number overflow Number overflow Number overflow
1E+2147483647, 0.1E2147483647 Number overflow Number overflow Number overflow
1.5E-2147483648, -1.5E-2147483648, 0.01E-2147483648 Number underflow Number underflow Number underflow
1E2147483648, 1E4294967296, 1E9223372036854775807 Number overflow cannot be converted Number overflow
1E-2147483649, 1E-9223372036854775808 Number underflow cannot be converted Number underflow
1E9223372036854775808, 1E-9223372036854775809 cannot be converted cannot be converted cannot be converted
0E2147483648, 0E9223372036854775806 Number overflow cannot be converted Number overflow
0E-9223372036854775807, 0E-9223372036854775808 Number underflow cannot be converted Number underflow
0E126, 0.0E-130 Number overflow, Number underflow 0 0 (#618)
0E9223372036854775807 Number underflow cannot be converted Number underflow
0.0E9223372036854775807 Number overflow not run Number overflow
40 digits (1234567890123456789012345678901234567890) with E9223372036854775768 Number overflow not run Number overflow
The same 40 digits with E9223372036854775767 the message for more than 38 digits not run the message for more than 38 digits
The same 40 digits with E9223372036854775769 or E9223372036854775807 Number overflow not run Number overflow

The second table covers the small side of the range. The DynamoDB column was measured on 2026-11-10 with the same PutItem request in us-east-1. Each value was sent twice, with the same answer both times. The ExtendDB columns are PutItem against dev-mode SQLite servers, run on 2026-11-10. The 39a41fb column ran on a server built from 58b177f, which differs from 39a41fb only in tests. The ebc5287 column ran on a server built from ebc5287. The 40 digits are 1234567890123456789012345678901234567891, and the 39 digits are 123456789012345678901234567890123456789. The column n is the exponent of the normalized form 0.d1d2... * 10^n, where d1 is the first nonzero digit. That exponent is the order of magnitude plus one. Each zero between the point and the digits lowers n by one. Values with n = i64::MIN - 1, i64::MIN - 2 and i64::MIN - 40 answer Number underflow. Values with n = i64::MIN and i64::MIN + 40 answer the message for more than 38 digits. The answers are the same with 39 digits and with 40 digits, and with both signs.

Value n DynamoDB this branch 39a41fb this branch ebc5287
.01234567890123456789012345678901234567891E-9223372036854775808 i64::MIN - 1 Number underflow the message for more than 38 digits Number underflow
.001234567890123456789012345678901234567891E-9223372036854775807 i64::MIN - 1 Number underflow the message for more than 38 digits Number underflow
.001234567890123456789012345678901234567891E-9223372036854775808 i64::MIN - 2 Number underflow the message for more than 38 digits Number underflow
.00000000000000000000000000000000000000001234567890123456789012345678901234567891E-9223372036854775808 (40 zeros) i64::MIN - 40 Number underflow the message for more than 38 digits Number underflow
.0123456789012345678901234567890123456789E-9223372036854775808 (39 digits) i64::MIN - 1 Number underflow the message for more than 38 digits Number underflow
-.01234567890123456789012345678901234567891E-9223372036854775808 i64::MIN - 1 Number underflow the message for more than 38 digits Number underflow
.1234567890123456789012345678901234567891E-9223372036854775808 i64::MIN the message for more than 38 digits the message for more than 38 digits the message for more than 38 digits
.01234567890123456789012345678901234567891E-9223372036854775807 i64::MIN the message for more than 38 digits the message for more than 38 digits the message for more than 38 digits
.001234567890123456789012345678901234567891E-9223372036854775806 i64::MIN the message for more than 38 digits the message for more than 38 digits the message for more than 38 digits
1234567890123456789012345678901234567891E-9223372036854775808 i64::MIN + 40 the message for more than 38 digits the message for more than 38 digits the message for more than 38 digits
.123456789012345678901234567890123456789E-9223372036854775808 (39 digits) i64::MIN the message for more than 38 digits the message for more than 38 digits the message for more than 38 digits
-.1234567890123456789012345678901234567891E-9223372036854775808 i64::MIN the message for more than 38 digits the message for more than 38 digits the message for more than 38 digits

DynamoDB starts each of these messages with 1 validation error detected: and ExtendDB does not. This PR does not change that difference.

Why

Closes #616. DynamoDB reads a number's exponent as a 64-bit value, and main reads it as a 32-bit value.

Testing done

  • Unit tests in number.rs: eight new tests, 29 tests in the module, all passing on ebc5287. On 39a41fb the module had 28 tests, all passing. At 58b177f, which adds the eighth test to the code of 39a41fb, 28 tests pass and one fails. magnitude_below_i64_min_is_an_underflow_before_the_digit_count fails at its first row, .01234567890123456789012345678901234567891E-9223372036854775808, with the message for more than 38 digits. Run against main 817b240's number.rs, two of the first five new tests fail on cannot be converted: exponent_is_read_as_i64 at 1E2147483648 and zero_with_exponent_outside_i32_is_range_checked at 0E2147483648. exponent_near_i32_limits_is_an_overflow_or_underflow, which failed on abf8082 with the overflow panic, passes on main since feat(core): backup format v1: streaming data files, sidecar manifest hash, typed backup ARN [backup/restore 3/4] #394. On the merge commit e80d018, the two tests that 39a41fb added fail with the answers the review reported. zero_with_exponent_at_i64_max_is_an_underflow gets Number overflow there. magnitude_at_i64_max_is_an_overflow_before_the_digit_count gets the message for more than 38 digits.
  • Wire tests in tests/rust/src/number_validation.rs: six new tests. Against a dev-mode SQLite server built from ebc5287, the number_validation filter passes 15 of 15 with --test-threads=1. Against a server built from 58b177f, 14 pass and put_item_magnitude_below_i64_min_is_underflow_before_digit_count fails at the same first row with the message for more than 38 digits. Against a server built from 39a41fb, the filter passed 14 of 14. The filter also matches main's update_item_number_validation.rs. In an earlier parallel run, 5 of the 14 failed with a transport error (DispatchGone) and no server error. The failing tests came from this branch and from main. Against main 817b240, put_item_exponent_near_i32_limits_is_overflow_or_underflow fails at 1E2147483648 and put_item_zero_with_exponent_outside_i32_is_rejected at 0E2147483648. put_item_exponent_outside_i64_is_malformed passes on main too.
  • At ebc5287, cargo +1.97.0 fmt --all -- --check is clean. Both clippy runs are clean with -D warnings: cargo +1.97.0 clippy --locked --all-targets --features extenddb-storage-cassandra/test-hooks,extenddb-storage-mongodb/test-hooks and cargo +1.97.0 clippy --locked --all-targets --features extenddb-engine/backup-test-hooks.
  • cargo fmt --all -- --check and cargo +1.97.0 clippy --locked -p extenddb-core --all-targets -- -D warnings are clean on 39a41fb. cargo test --locked -p extenddb-core --lib passed 1089 tests, with 1 ignored, one revision earlier. That revision differs from 39a41fb only in tests and comments. The passing tests include feat(core): backup format v1: streaming data files, sidecar manifest hash, typed backup ARN [backup/restore 3/4] #394's exponents_at_the_ends_of_i32_classify_the_magnitude, doc_examples_normalize_as_stated and exponent_at_the_end_of_i32_is_refused_as_an_overflow.
  • At the first revision, a probe sent zeros such as 0E126, -0E126 and 0.0E-130 as keys and attributes. It covered GetItem, Query, BatchGetItem, BatchWriteItem, TransactWriteItems, UpdateItem and DeleteItem. The output on the branch was the same as on main abf8082. For those zeros this branch and main 817b240 both return 0. The only check this PR adds on that path applies to an exponent outside i32.
  • CI at ebc5287: 63 of 63 checks passed.

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

None.


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.

validate_and_normalize_number parsed the exponent as an i32. #394 moved
its exponent sums to saturating i64 arithmetic, which fixed the overflow
panics of #616, but an exponent outside the i32 range was still refused
as malformed.

The exponent is now parsed as an i64 and the sums are done in i128
instead of saturating i64, so none of them can overflow. DynamoDB reads
the exponent the same way: 1E2147483648 is a Number overflow and
1E9223372036854775808 cannot be converted. A zero whose exponent does
not fit in an i32 is range checked too; main refused those as malformed.

A zero whose exponent fits in an i32 stays accepted as 0, although
DynamoDB refuses 0E126 and 0.0E-130. A refused zero keeps its raw
spelling in AttributeValue, and only the PutItem item and UpdateItem's
update values are validated afterwards, so UpdateItem's key and the
other operations would store 0E126 as a key separate from 0. #618
covers both.

Closes #616

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

@LeeroyHannigan I checked this change against live DynamoDB. The panic from #616 is fixed, and
the wrong message in release builds is fixed. No value panicked a debug build,
and no value wrapped on the paths that check numbers.

Two values still get the wrong message. I measured each one on live DynamoDB in
us-east-1. I sent each value two times, and both times gave the same answer.

  1. A zero with the exponent at the largest 64-bit value.

    PutItem with a non-key attribute {"N": "0E9223372036854775807"}.
    Live DynamoDB answers Number underflow. This change answers Number overflow.

    The neighbors show the edge. 0E9223372036854775806 answers Number overflow,
    and 0.0E9223372036854775807 answers Number overflow. Only the exponent at
    exactly the largest 64-bit value, with no fraction, answers Number underflow.

  2. More than 38 significant digits together with an out-of-range magnitude.

    PutItem with
    {"N": "1234567890123456789012345678901234567890E9223372036854775768"}.
    Live DynamoDB answers Number overflow. This change answers
    Attempting to store more than 38 significant digits in a Number.

    Live DynamoDB checks the magnitude before the digit count. The same value with
    the exponent one lower (...767) answers the digit-count message on both. So
    when the magnitude is out of range, the overflow or underflow message comes first.

Please change the code to match live DynamoDB for both values, and add the
measured values as test cases. The 64-bit exponent range is new in this change,
so both values reach these paths for the first time here.

The branch is a long way behind main. Please rebase it on current main so the
checks run against the current tree.

I will approve once both values match live DynamoDB and the branch is rebased.

Main has not changed crates/core/src/validation/number.rs or
tests/rust/src/number_validation.rs since this branch was cut. The
merge has no conflicting file and no edit outside the merge itself.
The core crate and its tests compile on the merged tree.
DynamoDB computes the exponent of a number's normalized form, the
order of magnitude plus one, in 64 bits. Two answers at the edge of
that range differed from ExtendDB's. PutItem in us-east-1 gave each
value below the same answer on two sends, on 9 or 10 Nov 2026.

A zero whose exponent is i64::MAX, with no fraction digit, is an
underflow: the sum wraps to a negative exponent. A fraction digit
lowers the exponent before the sum. So 0E9223372036854775807 is an
underflow, while 0E9223372036854775806 and 0.0E9223372036854775807
are overflows.

For a nonzero value whose sum is above i64::MAX, DynamoDB reports the
overflow before it counts the digits. Forty digits with
E9223372036854775768, E9223372036854775769 and E9223372036854775807
(an order of magnitude of i64::MAX, i64::MAX + 1 and i64::MAX + 39)
are overflows. The same digits with E9223372036854775767 are too many
digits. The one-digit 1E9223372036854775807 and 10E9223372036854775807
are overflows as well.

validate_and_normalize_number now computes the order of magnitude
before the digit count and applies both rules. The measured values
are unit tests in number.rs and wire tests in tests/rust, which check
the full message text.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@eliseong Both values now answer as you measured. 39a41fb computes the exponent of the normalized form, the order of magnitude plus one, in 64 bits:

  • 0E9223372036854775807 answers Number underflow, because the sum wraps. 0E9223372036854775806 and 0.0E9223372036854775807 stay Number overflow.
  • The 40 digits with E9223372036854775768 answer Number overflow before the digit count. With E9223372036854775767 they answer the message for more than 38 digits.

On 2026-11-10 I measured two more values the same way. The 40 digits with E9223372036854775769 and with E9223372036854775807 also answer Number overflow on DynamoDB. Both are in the tests with your five values, in number.rs and in tests/rust/src/number_validation.rs, and the wire tests now check the full message text. On the merge commit, without the fix, the two new unit tests fail with the answers you reported. Other spellings of these values follow the same rule and are not measured, for example -0E9223372036854775807.

I merged main at 887b6e2 (e80d018) instead of rebasing, which avoids a force push. CI now runs against current main. Main had not changed either file, and the merge has no conflicts.

@eliseong

eliseong commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

@LeeroyHannigan Thank you. F1 and F2 now match live DynamoDB. I confirmed both on live, two
sends each with the same answer both times.

  • 0E9223372036854775807 answers Number underflow.
  • A 40-digit mantissa with the exponent at E9223372036854775768 answers
    Number overflow, and one lower answers the digit-count message.

The large side of the exponent range is correct now. The small side has the
same miss that the large side had. When a number has more than 38 significant
digits and the normalized exponent is below the smallest 64-bit value, live
DynamoDB answers Number underflow before it counts the digits. This change
answers the digit-count message instead. I measured these on live, two sends
each, same answer both times.

  • .01234567890123456789012345678901234567891E-9223372036854775808: live
    answers Number underflow. This change answers Attempting to store more than 38 significant digits in a Number.
  • .001234567890123456789012345678901234567891E-9223372036854775807 (one past
    the edge): live answers Number underflow. This change answers the
    digit-count message.
  • The value at the exact edge answers the digit-count message on both.

This is the same rule as the overflow side, so please add the matching check for
the small side, with a test row for it.

I will approve once the small-side value matches live DynamoDB.

DynamoDB answers Number underflow before it counts the digits when
the normalized exponent is below the smallest 64-bit value. The
normalized form is 0.d * 10^n, with the first nonzero digit right
after the point. At that value, and above it, a number with more than
38 digits gets the 38-digit message. This is the mirror of the large
side, where the overflow comes first once the exponent is above the
largest 64-bit value.

PutItem in us-east-1 answered these twelve values on 2026-11-10, two
sends each, with the same answer both times. The digits are
1234567890123456789012345678901234567891 (40) and
123456789012345678901234567890123456789 (39). Each fraction zero
before the digits lowers the normalized exponent by one.

Number underflow, at i64::MIN - 1, i64::MIN - 2 and i64::MIN - 40:

  .0<40 digits>E-9223372036854775808
  .00<40 digits>E-9223372036854775807
  .00<40 digits>E-9223372036854775808
  .<40 zeros><40 digits>E-9223372036854775808
  .0<39 digits>E-9223372036854775808
  -.0<40 digits>E-9223372036854775808

The 38-digit message, at i64::MIN and at i64::MIN + 40:

  .<40 digits>E-9223372036854775808
  .0<40 digits>E-9223372036854775807
  .00<40 digits>E-9223372036854775806
  <40 digits>E-9223372036854775808
  .<39 digits>E-9223372036854775808
  -.<40 digits>E-9223372036854775808

The six underflow rows fail on the current code, which answers the
digit count for them. The fix follows in the next commit.

The date notes in both test files now name the values whose date
differs from their section's. 0E9223372036854775806 carries
2026-10-27. The rows of the two newest tests carry 2026-11-10.
The large side of the exponent range answers Number overflow before
the digit count once the normalized exponent is above i64::MAX. The
normalized form is 0.d * 10^n. The small side answered the digit count
for every number with more than 38 digits, whatever its exponent.
DynamoDB answers Number underflow before the digit count once that
exponent is below i64::MIN.

Add the mirror check next to the overflow check. A number with at most
38 digits this far down was an underflow already, through the range
check. Only numbers with more digits change their answer.

PutItem in us-east-1 answered the twelve values of the previous commit
on 2026-11-10, two sends each, with the same answer both times. The
normalized exponents i64::MIN - 1, i64::MIN - 2 and i64::MIN - 40 get
Number underflow. The exponents i64::MIN and i64::MIN + 40 get the
38-digit message. This holds with 40 digits, with 39 digits and with a
minus sign. The six underflow rows pass with this change, and the six
digit-count rows keep their answer.

@pdf-amzn pdf-amzn 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 agree with @eliseong's open point: I measured the small-side values too, and they still answer the digit-count message here. The other edge spellings I measured all match. What follows is AI generated:

Blocking: crates/core/src/validation/number.rs:118-124. There is no small-side counterpart to normalized_exponent_exceeds_i64. Measured 2026-11-10 19:39 UTC (us-east-1, PutItem non-key N, each value twice):

  • .01234567890123456789012345678901234567891E-9223372036854775808: DynamoDB answers Number underflow, this PR answers the digit-count message.
  • .001234567890123456789012345678901234567891E-9223372036854775807: same.
  • -.01234567890123456789012345678901234567891E-9223372036854775808: same.
  • .1234567890123456789012345678901234567891E-9223372036854775808 (normalized exactly i64::MIN): the digit-count message on both, correctly.

Fix: before the digit-count check, add if magnitude_exp + 1 < i128::from(i64::MIN) { return Err(underflow_err()); }, strict < to mirror > i64::MAX. Add unit rows next to magnitude_at_i64_max_is_an_overflow_before_the_digit_count and wire rows next to put_item_magnitude_at_i64_max_is_overflow_before_digit_count, with the edge value as the digit-count row. Update the doc comment on normalized_exponent_exceeds_i64 (line 150), or fold both sides into one helper.

Measured, no change needed: zeros on the small side. If DynamoDB wrapped the zero's point offset in 64 bits on this side as it does on the large side, 0.00E-9223372036854775808 would answer overflow. It doesn't. 0E-9223372036854775808, 0E-9223372036854775807, 0.0E-9223372036854775808, 0.00E-9223372036854775808, 0.000E-9223372036854775807 and 0.000E-9223372036854775808 all answer Number underflow on DynamoDB, and this PR matches.

Should-fix: the wire tests in tests/rust/src/number_validation.rs are dual-target, but CI only runs them against ExtendDB. I ran cargo test number_validation in tests/rust against real DynamoDB: all four new i64-edge tests pass there. Of the older tests, put_item_exponent_near_i32_limits_is_overflow_or_underflow and update_item_accepts_valid_number_in_expression failed with transport errors (no service answer; "runtime dropped the dispatch task"), which looks like the static CLIENT in test_base.rs being reused across #[tokio::test] runtimes. Not this PR's to fix. Separately, update_item_rejects_malformed_number_in_expression (unchanged here) failed for real: for 12e DynamoDB answered 1 validation error detected: The parameter cannot be converted to a numeric value: 12e, without the ExpressionAttributeValues contains invalid value wrapper the test expects. That's a question for main, not this PR.

Nit-or-follow-up: these spellings match DynamoDB on this PR (same measurement run) but have no test row, so a later refactor could change them unnoticed. Worth adding: -0E9223372036854775807, +0E9223372036854775807 and 0.E9223372036854775807 (underflow); 1E+09223372036854775807, -1E9223372036854775807 and 1E0000000000000000000002147483648 (overflow); 1E-09223372036854775808 (underflow).

Nit-or-follow-up: crates/core/src/validation/number.rs:145-148. digit_count uses i128::try_from(len).unwrap_or(i128::MAX) with the comment "always fits". The fallback can never run, and would answer wrongly if it did. .expect("usize fits in i128") states the invariant.

Nit-or-follow-up: crates/core/src/validation/number.rs:130. map_err(|_| overflow_err()) can't be reached, per the comment above it. If it were, it would hide a logic error as a user-facing overflow. Consider .expect(...).

@pdf-amzn

Copy link
Copy Markdown
Collaborator

my comment is out of date. rereviewing

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

Thanks. I pushed ebc5287 with the small side.

A nonzero number now answers Number underflow before the digit count when its normalized exponent, with the mantissa written as 0.d1d2..., is below the smallest 64-bit value. At the edge the digit count still runs.

I measured it on live DynamoDB on 2026-11-10, two sends each, with the same answer both times. Six values below the edge answer Number underflow: your two, one 2 steps below, one 40 steps below, a 39-digit value and a negative value. Six values at the edge or 40 steps above it answer the digit-count message, with 39 and 40 digits and both signs.

The unit test and the wire test both carry the twelve rows. The new rows failed before the fix and pass at ebc5287, and the description has the new table.

@pdf-amzn

Copy link
Copy Markdown
Collaborator

Nothing blocking from my side, I'll let Elise approve or not :)

From Kiro

I checked the new head, ebc5287:

It adds normalized_exponent_is_below_i64, which is the same strict magnitude_exp + 1 < i64::MIN check the review suggested.

It adds a unit test magnitude_below_i64_min_is_an_underflow_before_the_digit_count and a wire test put_item_magnitude_below_i64_min_is_underflow_before_digit_count.

I rebuilt it in the worktree. The core number tests pass, and all 17 probe values now match DynamoDB results. That includes the three that differed before.

Still open:

The seven measured spellings still have no test rows.

The two nits about fallbacks that can never run.

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

LGTM

The panic from #616 is fixed, and no number value wraps on the paths that check
numbers. I ran a debug build and sent exponents at the i32, i64, and i128 edges,
large mantissas, zeros with large exponents, and the same values as keys and as
attributes. None dropped the connection.

The number messages now match live DynamoDB at both ends of the 64-bit exponent
range. I measured these on live, two sends each with the same answer both times.

  • 0E9223372036854775807 answers Number underflow, and 0E9223372036854775806
    answers Number overflow.
  • A value with more than 38 digits and an order of magnitude above i64::MAX
    answers Number overflow before the digit count. The small side now matches
    too: the same value below i64::MIN answers Number underflow before the digit
    count, and the value at the edge answers the digit-count message.

The branch merges clean on current main.

@eliseong
eliseong added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 883f8c7 Nov 10, 2026
63 checks passed
@eliseong
eliseong deleted the fix/616-number-exponent-overflow branch November 10, 2026 20:51
LeeroyHannigan added a commit that referenced this pull request Nov 11, 2026
Main is 245 commits ahead of the merge base (817b240), up to
9c3fbfb. Six files conflicted.

- crates/core/src/validation/number.rs: main's reader, from #619 as
  merged, with this branch's operations module and magnitude limits.
  The merge drops check_zero_magnitude, since main's zero handling
  gives the same answers. The zero test keeps two rows that main lacks,
  0.00E-9223372036854775808 and 0.000E-9223372036854775808 (underflow
  on GetItem, measured 2026-10-27), and drops two rows that main's
  zero_with_exponent_at_i64_max_is_an_underflow covers.
- crates/core/src/expression/resolver.rs: main's two new ExpressionMaps
  fields and this branch's parsed_numerics type and comment.
- crates/engine/src/import_export.rs: main's AttributeNameRequestForm
  argument and this branch's log fields.
- crates/engine/src/put_item.rs: main's attribute name size checks,
  then this branch's item number check.
- crates/engine/src/transact_write_items.rs: the ClientRequestToken
  check, then main's attribute name size checks for every action, then
  the number check of each action after the handler prepares it.
- tests/rust/src/number_validation.rs: main's file, which holds this
  branch's rows and three later tests.

crates/engine/src/batch_write_item.rs merged without a conflict, with
the number check ahead of main's attribute name size checks. The merge
moves the number check after them, as in PutItem and
TransactWriteItems. delete_item.rs and update_item.rs merged without a
conflict: they check the key's numbers, then main's attribute name
sizes, then the numbers in ExpressionAttributeValues.

Measured in us-east-1 on 11 Nov 2026: an item held a 65,536-byte
attribute name and the number 1E2147483648. PutItem, BatchWriteItem
and TransactWriteItems gave either refusal on repeated sends.
TransactWriteItems reported a 37-character ClientRequestToken ahead of
both.
robinnsc added a commit that referenced this pull request Nov 18, 2026
Moves the workspace version from 0.1.15 to 1.0.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 14
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (version and the five platform pins), the
four licence-notice files (regenerated with cargo-about 0.9.0), and the
example `extenddb version` and `serve` output in docs/getting-started.md
and docs/manuals/04-quickstart-setup-guide.md.

RELEASED_THROUGH stays 12: migration 12 is still the last one, so 1.0.0
carries the catalog of 0.1.15 and freezes nothing new.

Upgrade manual:

- Behavior Changes by Release gets a v1.0.0 entry for #945: the
  Cassandra backend reads and writes at LOCAL_QUORUM where 0.1.15 ran
  many of them at ONE, so a request fails with HTTP 500 while fewer
  than a quorum of its keyspace's replicas are up. It says what to do
  before upgrading: a replication factor of 3, as cassandra-setup.md
  describes.
- Current Status, the General Upgrade Procedure and the Rollback
  Procedure cover 0.1.15 to 1.0.0, with that Cassandra step. Current
  Status says which of its paragraphs are for 0.1.14 and earlier and
  that the backup store notes apply to every deployment.
- A v0.1.15 entry for the request validation of #619, #620, #830 and
  #1000, which had none. It says the expression depth limit is
  ExtendDB's own.
- The rollback to 0.1.14 or earlier states what a binary of those
  releases does on a migrated catalog, as measured on PostgreSQL with
  0.1.14 and 0.1.10: exit status 1, "invalid catalog version '12'".

docs/versioning.md: the 0.1.x releases get no more fixes. The Docker Hub
pages name 0.1.15 as the first keyless-signed release.
docker/README-mongodb.md ran extenddb/extenddb-mongodb:0.1.8; it now
runs X.Y.Z, as the other image READMEs do.

doc_version_literals now reads docker/ as well, so a stale image tag
there fails it. It reports each image tag once, and skips another
project's image tag and a link to a release. The npm launcher test now
checks that the launcher refuses the release line before an X.0.0
launcher, which it skipped at patch 0.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
robinnsc added a commit that referenced this pull request Nov 18, 2026
Moves the workspace version from 0.1.15 to 1.0.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 14
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (version and the five platform pins), the
four licence-notice files (regenerated with cargo-about 0.9.0), and the
example `extenddb version` and `serve` output in docs/getting-started.md
and docs/manuals/04-quickstart-setup-guide.md.

RELEASED_THROUGH stays 12: migration 12 is still the last one, so 1.0.0
carries the catalog of 0.1.15 and freezes nothing new.

Upgrade manual:

- Behavior Changes by Release gets a v1.0.0 entry for #945: the
  Cassandra backend reads and writes at LOCAL_QUORUM where 0.1.15 ran
  many of them at ONE, so a request fails with HTTP 500 while fewer
  than a quorum of its keyspace's replicas are up. It says what to do
  before upgrading: a replication factor of 3, as cassandra-setup.md
  describes.
- A v1.0.0 entry for #1003. Without key_file the stored format and the
  catalog key stay as they are, and 0.1.15 and 1.0.0 each read the
  access keys the other wrote. serve and the backup commands refuse a
  catalog key that is not 32 bytes in base64, where 0.1.15 started and
  failed every signed request with HTTP 500; the entry says how to
  check the key before upgrading. The key moves into a locked key
  store, with a warning when the memlock limit is too low. key_file and
  the encryption-key commands are opt-in and link to the admin guide.
- The rollback section of #1003 now gives the PostgreSQL refusal of
  0.1.15 on a switched catalog: the encrypted connection string row
  stops it with exit status 1 before the missing key does.
- Current Status, the General Upgrade Procedure and the Rollback
  Procedure cover 0.1.15 to 1.0.0, with the Cassandra step, the key
  check, and the rollback after encryption-key switch. Current Status
  says which of its paragraphs are for 0.1.14 and earlier and that the
  backup store notes apply to every deployment.
- A v0.1.15 entry for the request validation of #619, #620, #830 and
  #1000, which had none. It says the expression depth limit is
  ExtendDB's own.
- The rollback to 0.1.14 or earlier states what a binary of those
  releases does on a migrated catalog, as measured on PostgreSQL with
  0.1.14 and 0.1.10: exit status 1, "invalid catalog version '12'".

docs/versioning.md: the 0.1.x releases get no more fixes. The Docker Hub
pages name 0.1.15 as the first keyless-signed release.
docker/README-mongodb.md ran extenddb/extenddb-mongodb:0.1.8; it now
runs X.Y.Z, as the other image READMEs do.

doc_version_literals now reads docker/ as well, so a stale image tag
there fails it. It reports each image tag once, and skips another
project's image tag and a link to a release. The npm launcher test now
checks that the launcher refuses the release line before an X.0.0
launcher, which it skipped at patch 0.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
LeeroyHannigan added a commit that referenced this pull request Nov 18, 2026
docs/manuals/07-upgrade-manual.md keeps the v0.1.15 entry that main adds for the request validation of #619, #620, #830 and #1000. The ClientRequestToken entry of this branch follows it.
amrith pushed a commit to amrith/extenddb that referenced this pull request Nov 20, 2026
Moves the workspace version from 0.1.15 to 1.0.0 on every surface that
carries it: the root Cargo.toml version and its 13 exact pins, the 14
workspace entries in Cargo.lock (no third-party entry changes),
packaging/npm/package.json (version and the five platform pins), the
four licence-notice files (regenerated with cargo-about 0.9.0), and the
example `extenddb version` and `serve` output in docs/getting-started.md
and docs/manuals/04-quickstart-setup-guide.md.

RELEASED_THROUGH stays 12: migration 12 is still the last one, so 1.0.0
carries the catalog of 0.1.15 and freezes nothing new.

Upgrade manual:

- Behavior Changes by Release gets a v1.0.0 entry for ExtendDB#945: the
  Cassandra backend reads and writes at LOCAL_QUORUM where 0.1.15 ran
  many of them at ONE, so a request fails with HTTP 500 while fewer
  than a quorum of its keyspace's replicas are up. It says what to do
  before upgrading: a replication factor of 3, as cassandra-setup.md
  describes.
- A v1.0.0 entry for ExtendDB#1003. Without key_file the stored format and the
  catalog key stay as they are, and 0.1.15 and 1.0.0 each read the
  access keys the other wrote. serve and the backup commands refuse a
  catalog key that is not 32 bytes in base64, where 0.1.15 started and
  failed every signed request with HTTP 500; the entry says how to
  check the key before upgrading. The key moves into a locked key
  store, with a warning when the memlock limit is too low. key_file and
  the encryption-key commands are opt-in and link to the admin guide.
- The rollback section of ExtendDB#1003 now gives the PostgreSQL refusal of
  0.1.15 on a switched catalog: the encrypted connection string row
  stops it with exit status 1 before the missing key does.
- Current Status, the General Upgrade Procedure and the Rollback
  Procedure cover 0.1.15 to 1.0.0, with the Cassandra step, the key
  check, and the rollback after encryption-key switch. Current Status
  says which of its paragraphs are for 0.1.14 and earlier and that the
  backup store notes apply to every deployment.
- A v0.1.15 entry for the request validation of ExtendDB#619, ExtendDB#620, ExtendDB#830 and
  ExtendDB#1000, which had none. It says the expression depth limit is
  ExtendDB's own.
- The rollback to 0.1.14 or earlier states what a binary of those
  releases does on a migrated catalog, as measured on PostgreSQL with
  0.1.14 and 0.1.10: exit status 1, "invalid catalog version '12'".

docs/versioning.md: the 0.1.x releases get no more fixes. The Docker Hub
pages name 0.1.15 as the first keyless-signed release.
docker/README-mongodb.md ran extenddb/extenddb-mongodb:0.1.8; it now
runs X.Y.Z, as the other image READMEs do.

doc_version_literals now reads docker/ as well, so a stale image tag
there fails it. It reports each image tag once, and skips another
project's image tag and a link to a release. The npm launcher test now
checks that the launcher refuses the release line before an X.0.0
launcher, which it skipped at patch 0.

Signed-off-by: Scott Robinson <robinnsc@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-blocker Must ship for its milestone's release security v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An N value with an exponent near the i32 limits panics the number validator in debug builds and gets the wrong error in release builds

4 participants