Skip to content

BigInt intrinsics do not handle BigInts sent between isolates #34752

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

Closed
alexmarkov opened this issue Oct 11, 2018 · 0 comments
Closed

BigInt intrinsics do not handle BigInts sent between isolates #34752

alexmarkov opened this issue Oct 11, 2018 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@alexmarkov
Copy link
Contributor

BigInt is backed by TypedData (Uint32List), which is converted to ExternalTypedData when sent between isolates if it exceeds certain size (kExternalizeTypedDataThreshold in raw_object_snapshot.cc).

However, BigInt intrinsics do no account for this and handle only regular TypedData. This results in incorrect behavior of arithmetic operations after receiving such BigInt.

Test:

import 'dart:io';
import 'dart:isolate';

import "package:expect/expect.dart";

const int kValue = 12345678;
const int kShift = 8192 * 8;

void verify(BigInt x) {
  BigInt y = x >> kShift;
  Expect.equals("$kValue", "$y");
}

void main() {
  BigInt big = BigInt.from(kValue) << kShift;
  verify(big);

  final rp = new ReceivePort();
  rp.listen((dynamic data) {
    BigInt received = data as BigInt;
    verify(received);
    BigInt x = received + BigInt.one - BigInt.one;
    verify(x);
    print("ok");
    exit(0);
  });
  rp.sendPort.send(big);
}

This issue is somewhat similar to flutter/flutter#22796, as it is also caused by morphing TypedData to ExternalTypedData when it is sent between isolates.

/cc @crelier @mraleph @rmacnak-google

@alexmarkov alexmarkov added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 11, 2018
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, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

1 participant