Skip to content

Fix float range check when decoding Unix time - #889

Merged
fxamacker merged 1 commit into
masterfrom
fxamacker/reduce-float64-unix-time-range
Oct 26, 2026
Merged

fxamacker merged 1 commit into
masterfrom
fxamacker/reduce-float64-unix-time-range

Conversation

@fxamacker

Copy link
Copy Markdown
Owner

When decoding Unix time encoded as floating-point, 2^63 seconds (about 292 billion years in the future) now returns the same UnmarshalTypeError as larger values. It is the only value affected, whether encoded as float32 or float64.

The check seconds > math.MaxInt64 is correct when both are integers, but seconds is float64 here, so math.MaxInt64 is converted to float64 and rounds up to 2^63.

This PR uses seconds >= math.MaxInt64 to account for the conversion.

When decoding Unix time encoded as floating-point, 2^63 seconds
(about 292 billion years in the future) now returns the same
UnmarshalTypeError as larger values.  It is the only value affected,
whether encoded as float32 or float64.

The check seconds > math.MaxInt64 is correct when both are integers,
but seconds is float64 here, so math.MaxInt64 is converted to float64
and rounds up to 2^63.

This commit uses seconds >= math.MaxInt64 to account for this.
@fxamacker fxamacker self-assigned this Oct 26, 2026
@fxamacker
fxamacker merged commit 49a20b9 into master Oct 26, 2026
19 checks passed
@fxamacker
fxamacker deleted the fxamacker/reduce-float64-unix-time-range branch October 27, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants