From 8c6f4a36de273ed334bb748a91f84d7f88d0bbdf Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 10 Mar 2021 16:45:02 -0800 Subject: [PATCH] Signal an error if an Isolate.spawnUri call uses an unsupported URI (flutter/engine#24583) --- engine/src/flutter/common/settings.h | 2 +- engine/src/flutter/runtime/dart_isolate.cc | 10 ++++++++++ engine/src/flutter/testing/dart/isolate_test.dart | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 engine/src/flutter/testing/dart/isolate_test.dart diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 5dcef45a17..4a914d89fa 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -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"; diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 68d27d11e8..8a236dc574 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -34,6 +34,8 @@ namespace flutter { namespace { +constexpr std::string_view kFileUriPrefix = "file://"; + class DartErrorString { public: DartErrorString() : str_(nullptr) {} @@ -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(new DartIsolateGroupData( diff --git a/engine/src/flutter/testing/dart/isolate_test.dart b/engine/src/flutter/testing/dart/isolate_test.dart new file mode 100644 index 0000000000..93124ce961 --- /dev/null +++ b/engine/src/flutter/testing/dart/isolate_test.dart @@ -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.spawnUri(Uri.parse('http://127.0.0.1/foo.dart'), [], null); + expect(() async => await isolate, throwsA(const TypeMatcher())); + }); +}