Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d20f90a

Browse files
committed
Signal an error if an Isolate.spawnUri call uses an unsupported URI
Fixes flutter/flutter#76371
1 parent a560c26 commit d20f90a

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

common/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct Settings {
118118

119119
// Used as the script URI in debug messages. Does not affect how the Dart code
120120
// is executed.
121-
std::string advisory_script_uri = "main.dart";
121+
std::string advisory_script_uri = "file:///main.dart";
122122
// Used as the script entrypoint in debug messages. Does not affect how the
123123
// Dart code is executed.
124124
std::string advisory_script_entrypoint = "main";

runtime/dart_isolate.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ namespace flutter {
3434

3535
namespace {
3636

37+
constexpr std::string_view kFileUriPrefix = "file://";
38+
3739
class DartErrorString {
3840
public:
3941
DartErrorString() : str_(nullptr) {}
@@ -929,6 +931,14 @@ Dart_Isolate DartIsolate::DartIsolateGroupCreateCallback(
929931
DartIsolateGroupData& parent_group_data =
930932
(*parent_isolate_data)->GetIsolateGroupData();
931933

934+
if (strncmp(advisory_script_uri, kFileUriPrefix.data(),
935+
kFileUriPrefix.size())) {
936+
std::string error_msg =
937+
std::string("Unsupported isolate URI: ") + advisory_script_uri;
938+
*error = fml::strdup(error_msg.c_str());
939+
return nullptr;
940+
}
941+
932942
auto isolate_group_data =
933943
std::make_unique<std::shared_ptr<DartIsolateGroupData>>(
934944
std::shared_ptr<DartIsolateGroupData>(new DartIsolateGroupData(

testing/dart/isolate_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:isolate';
7+
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('Invalid isolate URI', () async {
12+
final Future<Isolate> isolate = Isolate.spawnUri(Uri.parse('http://127.0.0.1/foo.dart'), <String>[], null);
13+
expect(() async => await isolate, throwsA(const TypeMatcher<IsolateSpawnException>()));
14+
});
15+
}

0 commit comments

Comments
 (0)