Skip to content

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

@m4tbat

Description

@m4tbat

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions