Skip to content

Unicode decimal digits in N values: refused on writes, compared as text on reads #565

Open

Description

@LeeroyHannigan

Observed on the service

Measured against DynamoDB (us-east-1) on 2026-10-25 at 11:31 and 12:56 UTC on tables with pk S and sk N, each read request sent twice.

  • PutItem with sk: {"N": "\uff11"} (fullwidth one) and a: {"N": "\u0661\u0662"} (Arabic-Indic one and two) is accepted.
  • GetItem on that item by the fullwidth key and by the ASCII key {"N": "1"} both return the item, and the item reads sk: {"N": "1"}, a: {"N": "12"}: the service stores the ASCII value.
  • GetItem on an item written with sk: {"N": "1"} by the fullwidth key {"N": "\uff11"} returns the item.
  • Query with sk = :n where :n is a fullwidth, Arabic-Indic or Devanagari one returns the item stored with sk N 1; a FilterExpression a = :f with the same digits matches an attribute stored as 1.
  • Query with an ExclusiveStartKey whose sk is a fullwidth zero returns the item stored with sk N 1, and with a fullwidth one (the item itself) returns nothing after it. A Scan with an ExclusiveStartKey written with a fullwidth one is accepted. {"N": "bob"} in the same position answers The parameter cannot be converted to a numeric value: bob on both.
  • Thirty nine Devanagari ones answer Attempting to store more than 38 significant digits in a Number, so the digits are parsed and counted as digits.
  • A superscript two (\u00b2), a vulgar half (\u00bd), a fullwidth minus (\uff0d1) and a fullwidth full stop (1\uff0e5) are refused with The parameter cannot be converted to a numeric value: <value as sent>.

The accepted characters are those of Unicode general category Nd (decimal digit); the refused ones are categories No, Pd and Po. The service reads the digits as their ASCII value when it stores or compares a number.

Observed on ExtendDB

On main:

  • PutItem with sk: {"N": "\uff11"}, or with a: {"N": "\uff11"}: ValidationException: The parameter cannot be converted to a numeric value: 1.
  • UpdateItem with SET b = :v, :v = {"N": "\uff11"}: ValidationException: ExpressionAttributeValues contains invalid value: The parameter cannot be converted to a numeric value: 1 for key :v.
  • GetItem with Key: {pk: {"S": "a"}, sk: {"N": "\uff11"}} on a table whose sort key is N: InternalServerError. The key values of GetItem, BatchGetItem, TransactGetItems and ExclusiveStartKey do not run the number validator, and the storage layer fails to parse the value.
  • Query and Scan with an ExclusiveStartKey written with a fullwidth digit on an N sort key: InternalServerError on SQLite and PostgreSQL.
  • Query and Scan compare a key condition or filter value written with a Unicode digit as the text the request sent, so it matches no item stored with the ASCII digit. A numeric sort key condition written that way answers InternalServerError on SQLite.

The write paths refuse because the number validator in crates/core/src/validation/number.rs accepts ASCII digits only. That validator runs on PutItem, UpdateItem, BatchWriteItem, TransactWriteItems and the condition expression values of DeleteItem.

Proposed change

Read a Unicode decimal digit as its ASCII value wherever a number is parsed, so writes store the ASCII value and reads compare it, as the service does. The fold table (the 68 run zeros of Unicode 15.0, each run ten consecutive code points) is in crates/engine/src/decimal_digits.rs once the Query number check lands, and can move to crates/core.

The value has to be read the same way by every consumer of a request. In particular, the server binds dynamodb:LeadingKeys from the partition key value of a Query, GetItem or write before the engine runs; if the engine reads a Unicode digit as a number and the binding does not, the two see different partitions. Folding the digits once, in the request body before authorization, gives both the same value.

Tests: GetItem, Query and Scan by a Unicode-digit key and ExclusiveStartKey, PutItem and UpdateItem with such a value read back as ASCII, and a dynamodb:LeadingKeys condition evaluated on the folded value.

Activity

  1. LeeroyHannigan commented on Nov 1, 2026

    @LeeroyHannigan
    CollaboratorAuthor

    PutItem on an N hash key and Scan with an ExclusiveStartKey on that key, measured against Amazon DynamoDB in us-east-1 on 31 October 2026, each request twice, both answers identical. Table pk N HASH (no sort key), items pk 1 to 6.

    PutItem on the hash key:

    Item Service ExtendDB main f49c5f823 (SQLite, release build)
    {"pk": {"N": "\uff19"}} (fullwidth nine) 200, a Scan then reads pk 9 ValidationException: The parameter cannot be converted to a numeric value: 9
    {"pk": {"N": "\u0667"}} (Arabic-Indic seven) 200, read back as 7 the number text with ٧
    {"pk": {"N": "\uff11\uff12.\uff15"}} (fullwidth digits around an ASCII full stop) 200, read back as 12.5 the number text with 12.5

    The table holds 1 to 6 after the three refusals. The 25 October rows had the sort key and a non-key attribute; this adds the hash key and a decimal written with mixed digits (25 October measured the fullwidth full stop as refused; 31 October measured an ASCII full stop between fullwidth digits as read).

    Scan with an ExclusiveStartKey on the hash key:

    ExclusiveStartKey Service ExtendDB main f49c5f823
    {"pk": {"N": "\uff11"}} 200, one item: the item after 1 in the table's order 200, Count 0, ScannedCount 0, no LastEvaluatedKey
    {"pk": {"N": "\u0661"}} the same one item the same as above
    {"pk": {"N": "+1"}} the same one item 200, the five items after 1

    So on a hash key the key is accepted and the scan answers an empty page where the 25 October rows on an N sort key answered InternalServerError on SQLite and PostgreSQL. A client paging with such a key reads the table as finished after 1. On the same server, Query pk = :p with FilterExpression a = :n and :n = {"N": "\uff11"} answers Count 0 on an item whose a is 1, as the issue describes.

    Code on main: validate_and_normalize_number (crates/core/src/validation/number.rs, lines 30 and 47) accepts ASCII digits only, which refuses the three PutItem rows. The Scan ExclusiveStartKey passes check_exclusive_start_key (crates/engine/src/index_helpers.rs), which compares the descriptor with the declared type and never reads the number, so the key reaches the storage layer as sent. The fix for #564 adds a number check on Scan's ExclusiveStartKey that reads these digits as numbers for the check; with it, the two keys above still answer 200 with no items.

  2. LeeroyHannigan commented on Nov 24, 2026

    @LeeroyHannigan
    CollaboratorAuthor

    More rows for a Query key value, measured in us-east-1 on 2026-11-24 for #481. Each request went out twice and got the same answer both times. Every request named a table that does not exist, so these answers come before the table lookup. The expression form is n = :v in KeyConditionExpression, and the legacy form is n with EQ in KeyConditions.

    Value Form DynamoDB UTC
    one U+FF11 expression ResourceNotFoundException (read as the number 1) 01:28:53
    39 U+FF11 expression and legacy Attempting to store more than 38 significant digits in a Number 01:28:53, 07:39:37
    683 U+FF11 expression and legacy the same 06:56:10
    700 U+FF11 expression and legacy the same 06:56:10
    2049 U+FF11 expression the same 03:05:26

    On #481's branch a value with a character outside ASCII is still sized as 0 bytes and passed on, as main does. On a SQLite server the Query then answers HTTP 200 with Count 0, or InternalServerError on an N sort key. tests/python holds no expected failures, so #481 keeps no wire row for these values. A fix here makes the 39, 683, 700 and 2049 rows answer the 38-digit sentence in both forms, and keeps one U+FF11 served.

  3. demohan commented on Nov 25, 2026

    @demohan
    Collaborator

    Two more shapes for this issue, from a Query on an N key (the GSI expression, the GSI KeyConditions, the base N partition key and the base N sort key), each sent twice to the service in us-east-1 and to SQLite builds of #481's head (ee58827) and of main 3534c9e:

    :v (N) Service, all four positions ExtendDB: GSI, KeyConditions, base HASH ExtendDB: base RANGE
    U+00A0 then 1 400 The parameter cannot be converted to a numeric value: followed by U+00A0 1 200, Count 0 500 InternalServerError
    U+FF11 then a 400 The parameter cannot be converted to a numeric value: 1a 200, Count 0 500 InternalServerError

    The service echoes U+FF11 then a as 1a, so it folds the digit before it reports the value. A no-break space is not read as a digit and is echoed as sent. The same table holds for 683, 700, 682 and 39 U+FF11, which the service answers with Attempting to store more than 38 significant digits in a Number.

  4. LeeroyHannigan commented on Nov 25, 2026

    @LeeroyHannigan
    CollaboratorAuthor

    More shapes for this issue, from demohan's review of #507 at bfbf7e373 (#507 (comment)). On a table that exists, a legacy ScanFilter, QueryFilter or KeyConditions value with U+FF11 or U+0661 reaches the storage layer as written. demohan counted 32 shapes:

    • ScanFilter, QueryFilter and a GSI key condition: ExtendDB answers 200 with Count 0. demohan measured that the service returns the item.
    • KeyConditions on an N sort key, with sk EQ, sk BETWEEN and sk BETWEEN [1E2, 5]: ExtendDB answers 500 InternalServerError.

    Main answers these as bfbf7e373 does. #507's earlier head 72b53241 refused them with the number text, which was also wrong. #507 leaves them to this issue. Its check now passes these digits, as the service does, and the read stays as on main.

    I ran the same groups again on a SQLite server of #507 at 08562698d. The table has pk S, sk N and a GSI on n N, and holds one item with sk, n and a set to 1. I sent each body twice and got the same answer both times:

    Body U+FF11 U+0661
    ScanFilter a EQ the digit 200, Count 0 200, Count 0
    KeyConditions pk EQ, QueryFilter a EQ the digit 200, Count 0 200, Count 0
    GSI KeyConditions n EQ the digit 200, Count 0 200, Count 0
    KeyConditions pk EQ, sk EQ the digit 500 500
    KeyConditions pk EQ, sk BETWEEN the digit and 5 500 500
    KeyConditions pk EQ, sk BETWEEN the digit with E2 and 5 500 500

    A SQLite server of 96713261a, which is bfbf7e373 with main merged in, gives the same answers.

  5. LeeroyHannigan commented on Nov 25, 2026

    @LeeroyHannigan
    CollaboratorAuthor

    One more shape for this issue, from demohan's review of #544 (#544 (comment)). The body is a Query with {"NS": ["1", "1"], "S": "x"} as :z in ExpressionAttributeValues: a fullwidth one (U+FF11) and an ASCII one, beside an S.

    Target Answer
    DynamoDB, us-east-1 ExpressionAttributeValues contains invalid value: Input collection contains duplicates for key :z
    ExtendDB on SQLite, #544's head 31c5f3d (merged as 1ddc087) ExpressionAttributeValues contains invalid value: Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes for key :z

    The body went twice to the service on 2026-11-25 at 06:23 UTC, with a table name that does not exist. It also went twice to the SQLite server. Each gave the same answer both times. I built the server from a commit on 31c5f3d that changes only comments and tests.

    The service reads 1 as 1, so the set holds the number 1 twice. On main, the number check folds the digit and accepts both members. The duplicate check, has_equal_numbers in crates/core/src/validation/number.rs, compares 1 as written and finds no duplicate. So the value gets the more than one datatypes text. A fix for this issue needs to fold the digits in that duplicate check too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions