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

Passing a _UnmodifiableUint8ArrayView to loadModuleFromBytes fails with a cryptic error #57039

Closed
jiahaog opened this issue Nov 6, 2024 · 1 comment
Assignees
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

@jiahaog
Copy link
Contributor

jiahaog commented Nov 6, 2024

This relates to package:dynamic_modules - cc @alexmarkov

Here's some flutter code to repro, but it should be simple to create one in pure dart.

import 'dart:io';
import 'dart:typed_data';

import 'package:dynamic_modules/dynamic_modules.dart' show loadModuleFromBytes;
import 'package:flutter/services.dart';

void main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();
  final ByteData data = await rootBundle.load('assets/dyn_module.bytecode');
  // `view` is a `_UnmodifiableUint8ArrayView`
  final view = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);

  // This throws the error below.
  await loadModuleFromBytes(view);

  // This works.
  final Uint8List bytes = Uint8List.fromList(view);
  await loadModuleFromBytes(bytes);
}

This is the cryptic error:

Unhandled Exception: Invalid argument(s): [51, 67, 66, 68, 1, 0, 0, 0, 0, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, ...
#0      _loadDynamicModule (dart:_internal-patch/internal_patch.dart:456:53)
#1      loadDynamicModule (dart:_internal-patch/internal_patch.dart:449:25)
#2      loadModuleFromBytes (package:dynamic_modules/dynamic_modules.dart:30:14)
#3      main (package:dynamic_module_counter/main.dart:19:17)
<asynchronous suspension>

I think it shouldn't even throw in the first place because _UnmodifiableUint8ArrayView implements Uint8List.

This was observed on Linux and on Android, at the 3067d697ae261b40aebbe0883c77cb873840867d Dart SDK revision.

@dart-github-bot
Copy link
Collaborator

Summary: The loadModuleFromBytes function in the dynamic_modules package throws an invalid argument error when passed a _UnmodifiableUint8ArrayView, even though it implements Uint8List. This issue occurs on Linux and Android, and the error message is unhelpful.

@dart-github-bot dart-github-bot added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 6, 2024
@alexmarkov alexmarkov self-assigned this Nov 6, 2024
@mraleph mraleph removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Nov 6, 2024
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

4 participants