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

VM DateTime fails to support 1 microsecond before epoch #55438

Closed
lrhn opened this issue Apr 11, 2024 · 1 comment
Closed

VM DateTime fails to support 1 microsecond before epoch #55438

lrhn opened this issue Apr 11, 2024 · 1 comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Apr 11, 2024

Example:

void main() {
  print(DateTime.utc(1969, 12, 31, 23, 59, 59, 999, 999));
}

fails with:

Unhandled exception:
Invalid argument(s)
#0      new DateTime._internal (dart:core-patch/date_patch.dart:54:23)
#1      new DateTime.utc (dart:core/date_time.dart:217:14)
#2      main (file:///usr/local/google/home/lrn/dart/sdk/sdk/dev/dtb.dart:2:18)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Likely caused by the code:

  @patch
  DateTime._internal(int year, int month, int day, int hour, int minute,
      int second, int millisecond, int microsecond, bool isUtc)
      : this.isUtc = checkNotNullable(isUtc, "isUtc"),
        this._value = _brokenDownDateToValue(year, month, day, hour, minute,
                second, millisecond, microsecond, isUtc) ??
            -1 {
    if (_value == -1) throw new ArgumentError();
  }

Nice hack, but the sentinel value is within the valid range.
Consider using -_maxMillisecondsSinceEpoch - 1 as sentinel instead.

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 11, 2024
@aam
Copy link
Contributor

aam commented Apr 11, 2024

https://dart-review.googlesource.com/c/sdk/+/362301 with the suggested fix. Thanks @lrhn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants