Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/core/src/error/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! Error message templates captured from real `DynamoDB`.
//! These are the exact messages `DynamoDB` returns — tenet 4 (errors are contracts).

use crate::validation::table_name_length::{TOO_LONG, TOO_SHORT};

/// Format a single validation constraint error in `DynamoDB`'s exact format.
#[must_use]
pub fn validation_error(value: &str, field: &str, constraint: &str) -> String {
Expand Down Expand Up @@ -71,12 +73,8 @@ pub enum ErrorMessageKey {
#[must_use]
pub fn error_message(key: ErrorMessageKey, args: &[&str]) -> String {
match key {
ErrorMessageKey::TableNameTooShort => {
format!("1 validation error detected: Value '{}' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3", args[0])
}
ErrorMessageKey::TableNameTooLong => {
format!("1 validation error detected: Value '{}' at 'tableName' failed to satisfy constraint: Member must have length less than or equal to 255", args[0])
}
ErrorMessageKey::TableNameTooShort => validation_error(args[0], "tableName", TOO_SHORT),
ErrorMessageKey::TableNameTooLong => validation_error(args[0], "tableName", TOO_LONG),
ErrorMessageKey::TableNameNull => {
"1 validation error detected: Value null at 'tableName' failed to satisfy constraint: Member must not be null".to_owned()
}
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub use warm_throughput::{
validate_warm_throughput_on_update,
};

pub mod table_name_length;

use crate::error::{DynamoDbError, ErrorMessageKey, error_message};
use crate::limits::LimitsConfig;
use crate::types::{
Expand Down
280 changes: 280 additions & 0 deletions crates/core/src/validation/table_name_length.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
// Copyright 2026 ExtendDB contributors
// SPDX-License-Identifier: Apache-2.0

//! A table name of a bad length, in the operations that look a table up by
//! it. These checks take the deployment's `[limits]` bounds, 3 to 255
//! characters by default, as [`validate_table_name`] does.
//!
//! The service refuses such a name with `ValidationException` before the
//! lookup, and answers a member of the wrong JSON type ahead of it: `GetItem`,
//! `BatchGetItem`, `BatchWriteItem` and `TransactWriteItems` answered
//! `SerializationException` for a short name beside a member of the wrong
//! type (measured 2026-11-18). So the handlers run these checks after the
//! request is read and before the first lookup. A name outside the pattern is
//! refused earlier, before authorization, by the server's table name gate,
//! which writes its length clauses with [`length_clause`] and the service's
//! bounds.
//!
//! An empty name gets other sentences from the service, which these checks
//! leave to the code after them, except in `GetItem` and `PutItem`.
//!
//! Ahead of those bounds the service checks the bound of the `TableName`
//! member, which also takes a table ARN: 1024 characters at most. A name over
//! it gets that clause, with no value quoted, at the member as the request
//! names it: `TableName`, `RequestItems.<key>` in `BatchGetItem`, and
//! `TransactItems.<n>.member.<Op>.TableName` with `n` counted from 0.
//! `BatchWriteItem` gives the map-key sentence with the member's list. The
//! clause comes alone, ahead of a name of 2 characters, a name outside the
//! pattern and an ARN that the ARN rules refuse (measured 2026-12-03). These
//! checks give it to a name that does not start with `arn:`. A deployment
//! whose maximum is above 1024 can create longer names, so for it the bound
//! is that maximum.

use crate::error::{
DynamoDbError, validation_error, validation_errors, validation_errors_detected,
};
use crate::limits::LimitsConfig;
use crate::types::TransactWriteItem;

use super::validate_table_name;

/// The constraint list of a `RequestItems` key that is not a table name the
/// service accepts (measured 2026-10-24 for a key outside the pattern and
/// 2026-11-18 for a key of a bad length).
pub const MAP_KEYS_NAME: &str = "Map keys must satisfy constraint: \
[Member must have length less than or equal to 255, \
Member must have length greater than or equal to 3, \
Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+]";

/// The clause of a table name under the minimum length. It names the
/// service's minimum, 3, whatever the deployment's is, as the sentence of
/// [`validate_table_name`] does.
pub(crate) const TOO_SHORT: &str = "Member must have length greater than or equal to 3";

/// The clause of a table name over the maximum length, which names the
/// service's maximum, 255, in the same way.
pub(crate) const TOO_LONG: &str = "Member must have length less than or equal to 255";

/// The bound of the `TableName` member, in characters.
const MEMBER_MAX: usize = 1024;

/// The clauses of the `TableName` member's bounds.
const MEMBER_TOO_SHORT: &str = "Member must have length greater than or equal to 1";
const MEMBER_TOO_LONG: &str = "Member must have length less than or equal to 1024";

/// The constraint list of a `BatchWriteItem` `RequestItems` key over the
/// member's bound (measured 2026-12-03).
const MAP_KEYS_MEMBER: &str = "Map keys must satisfy constraint: \
[Member must have length less than or equal to 1024, \
Member must have length greater than or equal to 1]";

/// The length clause a table name fails under the bounds `(min, max)`, in
/// characters, or `None` for a name within them.
#[must_use]
pub fn length_clause(name: &str, (min, max): (usize, usize)) -> Option<&'static str> {

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.

For a name over 1024 characters, the service answers GetItem, BatchGetItem and TransactWriteItems with Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024 and no value quoted (at RequestItems.<key>, or TransactItems.<n>.member.<Op>.TableName), and in a transaction that error alone, even beside an ab name; this head gives the 255 clause. At exactly 1024 the service gives the 255 clause, as this head does.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in aedd59a. A name over 1024 characters now gets the clause of the member bound, with no value quoted, at the member as the request names it. I measured each row in us-east-1 on 3 Dec, and sent each request twice:

  • GetItem and PutItem: 1 validation error detected: Value at 'TableName' failed to satisfy constraint: Member must have length less than or equal to 1024.
  • BatchGetItem: Value at 'RequestItems.<key>', one clause for each such key. With two such keys the service listed them in either order on two sends, and ExtendDB lists them sorted.
  • BatchWriteItem: the map keys sentence at requestItems with the list [Member must have length less than or equal to 1024, Member must have length greater than or equal to 1]. ExtendDB quotes the key alone (BatchGetItem and BatchWriteItem quote a refused RequestItems key alone, where DynamoDB quotes the whole RequestItems value #1118).
  • TransactWriteItems: Value at 'TransactItems.<n>.member.<Op>.TableName', with n counted from 0, one clause for each such name. It comes alone beside an ab action, a bad name action and an ARN of the vendor s3. The gate gives this answer when it refuses the request for one of the last two.

At 1024 characters GetItem and TransactWriteItems keep the 255 clause. The checks are in crates/core/src/validation/table_name_length.rs, and the rows are in table_name_length_tests.rs, the gate test and TestTableNameLengths. A deployment whose max_table_name_length is above 1024 takes that maximum as the bound, so it can still use the names it creates.

match name.chars().count() {
n if n < min => Some(TOO_SHORT),
n if n > max => Some(TOO_LONG),
_ => None,
}
}

/// The deployment's table name bounds `(min, max)`: the `[limits]` values
/// `min_table_name_length` and `max_table_name_length`, 3 and 255 by default.
#[must_use]
pub fn table_name_bounds(limits: &LimitsConfig) -> (usize, usize) {
(limits.min_table_name_length, limits.max_table_name_length)
}

/// Where the service reports the table name of a `TransactItems` action:
/// `transactItems.<n>.member.<op>.tableName`, with `n` counted from 1 and the
/// action's member name (`ConditionCheck`) in lower camel case.
#[must_use]
pub fn transact_name_location(index: usize, member: &str) -> String {
let mut chars = member.chars();
let op = match chars.next() {
Some(first) => first.to_ascii_lowercase().to_string() + chars.as_str(),
None => String::new(),
};
format!("transactItems.{}.member.{op}.tableName", index + 1)
}

/// A name over the bound of the `TableName` member and over the
/// deployment's maximum `max`, so that a name the deployment can create is
/// never refused for it. A table ARN is left to the code after these checks.
fn over_member_bound(name: &str, max: usize) -> bool {
!name.starts_with("arn:") && name.chars().count() > MEMBER_MAX.max(max)
}

/// The service's message for members outside the `TableName` member's
/// bounds: one `Value at '<location>'` clause for each, with no value quoted.
fn member_error(clauses: impl IntoIterator<Item = (String, &'static str)>) -> DynamoDbError {
let clauses: Vec<String> = clauses
.into_iter()
.map(|(location, constraint)| {
format!("Value at '{location}' failed to satisfy constraint: {constraint}")
})
.collect();
DynamoDbError::ValidationException(validation_errors_detected(&clauses))
}

/// The table name check `GetItem` and `PutItem` run before the lookup. The
/// service answers an empty name and a name over 1024 characters in both
/// with `Value at 'TableName'` and the member's bound (measured 2026-11-18
/// and 2026-12-03). Any other name gets the answer of
/// [`validate_table_name`].
///
/// # Errors
///
/// `ValidationException` for a name outside the member's bounds or one that
/// [`validate_table_name`] refuses.
pub fn validate_item_table_name(name: &str, limits: &LimitsConfig) -> Result<(), DynamoDbError> {
let constraint = if name.is_empty() {
MEMBER_TOO_SHORT
} else if over_member_bound(name, limits.max_table_name_length) {
MEMBER_TOO_LONG
} else {
return validate_table_name(name, limits);
};
Err(member_error([("TableName".to_owned(), constraint)]))
}

/// A `RequestItems` key of a bad length in `operation`, `BatchGetItem` or
/// `BatchWriteItem`. A key over 1024 characters gets the member's bound (see
/// the module comment); any other gets the map-key sentence at
/// `requestItems`. Where the service quotes its rendering of the whole map in
/// `Value '...'`, this renders the key alone, as the server's table name gate
/// does for a key outside the pattern. An empty key and a table ARN are left
/// to the code after this.
///
/// # Errors
///
/// `ValidationException`. The keys come from a `HashMap`, whose order
/// changes from one request to the next, so they are taken in sorted order:
/// a sentence that quotes one key quotes the smallest, and `BatchGetItem`
/// lists the keys over 1024 characters sorted, where the service listed two
/// of them in either order.
pub fn validate_request_items_keys<'a>(
operation: &str,
keys: impl IntoIterator<Item = &'a String>,
limits: &LimitsConfig,
) -> Result<(), DynamoDbError> {
let mut keys: Vec<&str> = keys
.into_iter()
.map(String::as_str)
.filter(|k| !k.is_empty() && !k.starts_with("arn:"))
.collect();
keys.sort_unstable();
let over: Vec<&str> = keys
.iter()
.copied()
.filter(|k| over_member_bound(k, limits.max_table_name_length))
.collect();
if let Some(key) = over.first() {
return Err(if operation == "BatchWriteItem" {
DynamoDbError::ValidationException(validation_error(
key,
"requestItems",
MAP_KEYS_MEMBER,
))
} else {
member_error(
over.iter()
.map(|k| (format!("RequestItems.{k}"), MEMBER_TOO_LONG)),
)
});
}
let bounds = table_name_bounds(limits);
if let Some(key) = keys.iter().find(|k| length_clause(k, bounds).is_some()) {
return Err(DynamoDbError::ValidationException(validation_error(
key,
"requestItems",
MAP_KEYS_NAME,
)));
}
Ok(())
}

/// The `TransactItems` names over 1024 characters and over the deployment's
/// maximum `max`, each `(action index, member, name)` with the member as the
/// request writes it (`Put`), in the order given, at
/// `TransactItems.<n>.member.<Op>.TableName`. The service lists them alone,
/// ahead of every other name fault of the request (see the module comment).
///
/// # Errors
///
/// `ValidationException` listing each such name.
pub fn check_transact_member_bound<'a>(
names: impl IntoIterator<Item = (usize, &'a str, &'a str)>,
max: usize,
) -> Result<(), DynamoDbError> {
let over: Vec<(String, &str)> = names
.into_iter()
.filter(|(_, _, name)| over_member_bound(name, max))
.map(|(i, member, _)| {
(
format!("TransactItems.{i}.member.{member}.TableName"),
MEMBER_TOO_LONG,
)
})
.collect();
if over.is_empty() {
return Ok(());
}
Err(member_error(over))
}

/// The table names of a bad length in the actions of a `TransactWriteItems`
/// request: the names over 1024 characters (see
/// [`check_transact_member_bound`]), or else every action's fault of the
/// deployment's bounds in one message, in action order (measured
/// 2026-11-18). An empty name and a table ARN are left to the code after
/// this.
///
/// # Errors
///
/// `ValidationException` listing each such name.
pub fn validate_transact_write_names(
items: &[TransactWriteItem],
limits: &LimitsConfig,
) -> Result<(), DynamoDbError> {
let mut names: Vec<(usize, &str, &str)> = Vec::new();
for (i, item) in items.iter().enumerate() {
let members = [
(
"ConditionCheck",
item.condition_check.as_ref().map(|o| &o.table_name),
),
("Put", item.put.as_ref().map(|o| &o.table_name)),
("Delete", item.delete.as_ref().map(|o| &o.table_name)),
("Update", item.update.as_ref().map(|o| &o.table_name)),
];
for (member, name) in members {
if let Some(name) = name.filter(|n| !n.is_empty() && !n.starts_with("arn:")) {
names.push((i, member, name));
}
}
}
check_transact_member_bound(names.iter().copied(), limits.max_table_name_length)?;
let bounds = table_name_bounds(limits);
let located: Vec<(&str, String, &str)> = names
.iter()
.filter_map(|&(i, member, name)| {
Some((
name,
transact_name_location(i, member),
length_clause(name, bounds)?,
))
})
.collect();
if located.is_empty() {
return Ok(());
}
let faults: Vec<(&str, &str, &str)> = located
.iter()
.map(|(name, location, clause)| (*name, location.as_str(), *clause))
.collect();
Err(DynamoDbError::ValidationException(validation_errors(
&faults,
)))
}
8 changes: 1 addition & 7 deletions crates/engine/src/backup_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use extenddb_core::error::DynamoDbError;
use extenddb_core::limits::LimitsConfig;
use extenddb_core::types::BackupSummary;
use extenddb_core::validation::table_name_length::table_name_bounds;
use extenddb_core::validation::validate_name_member;
use extenddb_storage::backup_catalog::TimeBounds;
use extenddb_storage::error::StorageError;
Expand Down Expand Up @@ -87,13 +88,6 @@ pub(crate) fn required_str<'a>(
})
}

/// The length bounds for a `TableName` member: the deployment's, which
/// default to the model's 3 to 255. `CreateTable` takes the same bounds, so a
/// table the deployment could create can be backed up and listed.
fn table_name_bounds(limits: &LimitsConfig) -> (usize, usize) {
(limits.min_table_name_length, limits.max_table_name_length)
}

/// The `TableName` of `CreateBackup` and `ListBackups`, which the service
/// accepts as the table's name or its ARN (measured on DynamoDB; the model
/// gives the member the `TableName` shape, max 255, so an SDK built from it
Expand Down
6 changes: 6 additions & 0 deletions crates/engine/src/batch_get_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ pub async fn handle_batch_get_item(
extenddb_core::validation::number::operations::batch_get_keys(keys)?;
}

extenddb_core::validation::table_name_length::validate_request_items_keys(
"BatchGetItem",
input.request_items.keys(),
&ctx.limits,
)?;

let mut responses: HashMap<String, Vec<Item>> = HashMap::new();
let mut total_rcu: f64 = 0.0;
let mut total_pre_proj_bytes: usize = 0;
Expand Down
9 changes: 9 additions & 0 deletions crates/engine/src/batch_write_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ pub async fn handle_batch_write_item(
.collect();
request_limits::check_batch_counts("BatchWriteItem", &counts)?;

// A key of a bad length comes ahead of a WriteRequest that holds no
// request, an attribute name over the size limit and a number the service
// cannot read (measured 2026-12-03).
extenddb_core::validation::table_name_length::validate_request_items_keys(
"BatchWriteItem",
input.request_items.keys(),
&ctx.limits,
)?;

// Validate: each WriteRequest has exactly one of PutRequest or DeleteRequest
for reqs in input.request_items.values() {
for wr in reqs {
Expand Down
12 changes: 12 additions & 0 deletions crates/engine/src/get_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ pub async fn handle_get_item(
None => None,
};

// See core's table_name_length for this order. An ARN is checked after the lookup.
if !input.table_name.starts_with("arn:") {
extenddb_core::validation::table_name_length::validate_item_table_name(
&input.table_name,
&ctx.limits,
)?;
}

let key_info = ctx
.table_key_info(&input.table_name)
.await
Expand Down Expand Up @@ -172,3 +180,7 @@ pub async fn handle_get_item(
},
})
}

#[cfg(all(test, feature = "partiql"))]
#[path = "table_name_length_tests.rs"]
mod table_name_length_tests;
2 changes: 1 addition & 1 deletion crates/engine/src/partiql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod returning;
mod select;
mod snapshot;
#[cfg(test)]
mod test_context;
pub(crate) mod test_context;
mod transaction;
mod write;

Expand Down
Loading
Loading