Skip to content

BigInt intrinsics do not handle BigInts sent between isolates #34752

Closed
@alexmarkov

Description

@alexmarkov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions