Skip to content

Validate Timestamp values are within spec's range#3550

Merged
oldergod merged 1 commit intomasterfrom
bquenaudon.2026-03-18.timestamprange
Mar 23, 2026
Merged

Validate Timestamp values are within spec's range#3550
oldergod merged 1 commit intomasterfrom
bquenaudon.2026-03-18.timestamprange

Conversation

@oldergod
Copy link
Member

Fixes #3548

@oldergod oldergod force-pushed the bquenaudon.2026-03-18.timestamprange branch from c4c820e to 840d114 Compare March 18, 2026 12:41
@oldergod oldergod marked this pull request as ready for review March 18, 2026 12:41
@oldergod oldergod force-pushed the bquenaudon.2026-03-18.timestamprange branch from 840d114 to ee58484 Compare March 18, 2026 13:02
.setOrderedAt(
Timestamp.newBuilder()
.setSeconds(-631152000000L) // 1950-01-01T00:00:00.250Z.
.setSeconds(-631152000L) // 1950-01-01T00:00:00.250Z.
Copy link
Member Author

Choose a reason for hiding this comment

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

we were passing ms... instead of s !

Copy link
Member Author

Choose a reason for hiding this comment

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

interestingly, protoc didn't throw though?

Copy link
Collaborator

@JakeWharton JakeWharton left a comment

Choose a reason for hiding this comment

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

I have no real opinion on this. Is the adapter's encode functions the right places to throw, or should it be validated once in the constructor of the message?

@oldergod
Copy link
Member Author

Hmmm, I was matching protoc behavior but being able to instantiate an invalid object is definitely weird... I'll think a bit

@mdub
Copy link

mdub commented Mar 20, 2026

I looked for other range-checking code (in Wire), but couldn't find any. Makes me wonder whether lack of validation was a deliberate design decision?

@oldergod
Copy link
Member Author

@mdub I don't think that this is deliberate, no.

@oldergod
Copy link
Member Author

Not sure how we would gracefully validate that on creation since we're typealiasing to java.time.Instant on the JVM.
Let's go with the serialisation for now

@oldergod oldergod merged commit 0fa1a7b into master Mar 23, 2026
17 checks passed
@oldergod oldergod deleted the bquenaudon.2026-03-18.timestamprange branch March 23, 2026 11:57
@JakeWharton
Copy link
Collaborator

You'd validate in each constructor of a message containing the value

@oldergod
Copy link
Member Author

I thought of it but say the request/response type of an RPC is timestamp?

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.

Timestamp ProtoAdapter silently encodes out-of-range Instant values

3 participants