Skip to content

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

@jiahaog

Description

@jiahaog

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.

Metadata

Metadata

Assignees

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