Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp serialization fails on large deltas from epoch #6892

Closed
nielsenko opened this issue Aug 15, 2023 · 4 comments
Closed

Timestamp serialization fails on large deltas from epoch #6892

nielsenko opened this issue Aug 15, 2023 · 4 comments

Comments

@nielsenko
Copy link
Contributor

nielsenko commented Aug 15, 2023

Realm represent timestamps as 64 bit seconds offset from epoch (1970) and a 32 bit nano-seconds component. Hence realm can represent offsets from epoch up to (1 << 63)s / 86400s/day = 9223372036854689408 days.

The buffer used to serialize is just 32 bytes. From timestamp.hpp:202:

    char buffer[32];
    out << d.to_string(buffer);

The largest year representable with a realm timestamp is roughly (1 <<63)s / 86400s/day / 365day/years = 292471208677years. Hence we need 13 (12 + 1 for sign) bytes just for the years. Then 14 for %m-%d %H:%M:%S and another 10 for the nanoseconds and the preceding . which is 37 altogether.

A true iso8601 serialized utc timestamp also has a Z at the end and T separating date from time instead of a space.

Core version: 13.17.2

@nielsenko
Copy link
Contributor Author

@rorbech & @cmelchior I believe the Java SDK is actually impacted by this. For Dart it is just some test cases that fails.

@rorbech
Copy link
Contributor

rorbech commented May 22, 2024

This also fails for Kotlin's RealmInstant.MIN.

Callint:

realm::Timestamp::to_string(std::__ndk1::array<…> &) const serializer.cpp:128

With:

this = {const realm::Timestamp *} 0x72a7d14148 
 m_seconds = {int64_t} -9223372036854775808
 m_nanoseconds = {int32_t} -999999999
 m_is_null = {bool} false

Will generate this string:

"-188\xde-01-5: 15:30:07.000000001"

@rorbech
Copy link
Contributor

rorbech commented Aug 9, 2024

Serialization of Kotlin's RealmInstant.MIN is fixed by #7934.

@nielsenko
Copy link
Contributor Author

I guess I can close my PR then

@sync-by-unito sync-by-unito bot closed this as completed Aug 16, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants