Skip to content

Commit

Permalink
Signal an error if an Isolate.spawnUri call uses an unsupported URI (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons authored Mar 11, 2021
1 parent 21a484d commit 4813ed0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct Settings {

// Used as the script URI in debug messages. Does not affect how the Dart code
// is executed.
std::string advisory_script_uri = "main.dart";
std::string advisory_script_uri = "file:///main.dart";
// Used as the script entrypoint in debug messages. Does not affect how the
// Dart code is executed.
std::string advisory_script_entrypoint = "main";
Expand Down
10 changes: 10 additions & 0 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace flutter {

namespace {

constexpr std::string_view kFileUriPrefix = "file://";

class DartErrorString {
public:
DartErrorString() : str_(nullptr) {}
Expand Down Expand Up @@ -929,6 +931,14 @@ Dart_Isolate DartIsolate::DartIsolateGroupCreateCallback(
DartIsolateGroupData& parent_group_data =
(*parent_isolate_data)->GetIsolateGroupData();

if (strncmp(advisory_script_uri, kFileUriPrefix.data(),
kFileUriPrefix.size())) {
std::string error_msg =
std::string("Unsupported isolate URI: ") + advisory_script_uri;
*error = fml::strdup(error_msg.c_str());
return nullptr;
}

auto isolate_group_data =
std::make_unique<std::shared_ptr<DartIsolateGroupData>>(
std::shared_ptr<DartIsolateGroupData>(new DartIsolateGroupData(
Expand Down
15 changes: 15 additions & 0 deletions testing/dart/isolate_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:isolate';

import 'package:test/test.dart';

void main() {
test('Invalid isolate URI', () async {
final Future<Isolate> isolate = Isolate.spawnUri(Uri.parse('http://127.0.0.1/foo.dart'), <String>[], null);
expect(() async => await isolate, throwsA(const TypeMatcher<IsolateSpawnException>()));
});
}

0 comments on commit 4813ed0

Please sign in to comment.