Skip to content

Return a PayloadError for out of range EPOCH_SECONDS timestamps - #2022

Open
sebxt wants to merge 1 commit into
disneystreaming:series/0.19from
sebxt:fix/epoch-seconds-out-of-range-decode
Open

sebxt wants to merge 1 commit into
disneystreaming:series/0.19from
sebxt:fix/epoch-seconds-out-of-range-decode

Conversation

@sebxt

@sebxt sebxt commented Oct 20, 2026

Copy link
Copy Markdown

Decoding an epoch-seconds timestamp from JSON or a Document called Timestamp.apply without a range check, so out of range values threw IllegalArgumentException instead of PayloadError (a 500 instead of a 400 on a server), and values beyond the Long range wrapped around silently (18446744073709551621 decoded to 1970-01-01T00:00:05Z). The JSON key decoder also truncated toward zero, so negative fractional keys such as "-1.5", which the encoder produces, could not be decoded.

This adds a private[smithy4s] helper, Timestamp.fromEpochSecondsDecimal, that rounds down, checks the range on the BigDecimal before converting to Long, and returns an Option. The JSON value and key decoders and the Document decoder use it and raise a decode error on None, the same way #2010 handled the other time primitives.

PR Checklist (not all items are relevant to all PRs)

  • Added unit-tests (for runtime code)
  • Added bootstrapped code + smoke tests (when the rendering logic is modified)
  • Added build-plugins integration tests (when reflection loading is required at codegen-time)
  • Added alloy compliance tests (when simpleRestJson protocol behaviour is expanded/updated)
  • Updated dynamic module to match generated-code behaviour
  • Added documentation
  • Updated changelog

Fixes #2021

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Out of range EPOCH_SECONDS timestamps throw IllegalArgumentException or wrap around when decoded

2 participants