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

[cloud_firestore]: Creating Timestamp from DateTimes before 1970-01-01 could throw due to invalid nanosecond calculation #17189

Closed
1 task done
m4tbat opened this issue Mar 13, 2025 · 0 comments · Fixed by #17195
Assignees
Labels
Needs Attention This issue needs maintainer attention. platform: all Issues / PRs which are for all platforms. plugin: cloud_firestore type: bug Something isn't working

Comments

@m4tbat
Copy link

m4tbat commented Mar 13, 2025

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Cloud Firestore

Which platforms are affected?

Android, iOS, macOS, Web, Windows

Description

Creating a Timestamp (from package cloud_firestore_platform_interface) with the factories fromMicrosecondsSinceEpoch and fromMillisecondsSinceEpoch, passing a negative value with non-zero millisecond value (which could come from a DateTime object representing a date before 1970-01-01, causes _validateRange to throw because it fails the precondition _check(nanoseconds >= 0, 'nanoseconds', nanoseconds);.

The thrown exception is
Invalid argument(s): Timestamp nanoseconds out of range: -<nanoseconds>

This is due to erroneous calculation of nanoseconds in the body of the aforementioned factories.

Reproducing the issue

final date = DateTime(1969, 06, 22, 0, 0, 0, 123);
final timestamp = Timestamp.fromDate(date); // this throws

Firebase Core version

3.12.1

Flutter Version

3.29.1

Relevant Log Output

Flutter dependencies

No response

Additional context and comments

No response

@m4tbat m4tbat added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Mar 13, 2025
@SelaseKay SelaseKay added plugin: cloud_firestore platform: all Issues / PRs which are for all platforms. labels Mar 13, 2025
@SelaseKay SelaseKay self-assigned this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention This issue needs maintainer attention. platform: all Issues / PRs which are for all platforms. plugin: cloud_firestore type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants