From 0300dd8ba2222e34ac3655f1f6667f9f56ea00a7 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Fri, 3 Jul 2020 00:17:38 +0200 Subject: [PATCH] Fix crash on inspector setScriptSource calls when source is unchanged Bug: chromium:1059746 Change-Id: I309c15a33a7185c9397b7893a9eefcb90981dc64 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2280085 Commit-Queue: Yang Guo Reviewed-by: Yang Guo Cr-Commit-Position: refs/heads/master@{#68713} --- AUTHORS | 3 ++- src/inspector/v8-debugger-script.cc | 4 +++- .../set-script-source-unchanged-expected.txt | 1 + .../debugger/set-script-source-unchanged.js | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/inspector/debugger/set-script-source-unchanged-expected.txt create mode 100644 test/inspector/debugger/set-script-source-unchanged.js diff --git a/AUTHORS b/AUTHORS index 7c43c60fc1..2a58b0e1c3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,6 +42,7 @@ Cloudflare, Inc. <*@cloudflare.com> Julia Computing, Inc. <*@juliacomputing.com> Aaron Bieber +Aaron O'Mullan Abdulla Kamar Adam Kallai Akinori MUSHA @@ -216,4 +217,4 @@ Zhongping Wang 柳荣一 Yanbo Li Gilang Mentari Hamidy -Zeynep Cankara \ No newline at end of file +Zeynep Cankara diff --git a/src/inspector/v8-debugger-script.cc b/src/inspector/v8-debugger-script.cc index 6e54656d40..7a16f9f644 100644 --- a/src/inspector/v8-debugger-script.cc +++ b/src/inspector/v8-debugger-script.cc @@ -174,7 +174,9 @@ class ActualScript : public V8DebuggerScript { result->message = scope.Escape(result->message); return; } - if (preview) return; + // NOP if preview or unchanged source (diffs.empty() in PatchScript) + if (preview || result->script.IsEmpty()) return; + m_hash = String16(); Initialize(scope.Escape(result->script)); } diff --git a/test/inspector/debugger/set-script-source-unchanged-expected.txt b/test/inspector/debugger/set-script-source-unchanged-expected.txt new file mode 100644 index 0000000000..13e3fbcf81 --- /dev/null +++ b/test/inspector/debugger/set-script-source-unchanged-expected.txt @@ -0,0 +1 @@ +Check that setScriptSource does not crash when source is unchanged diff --git a/test/inspector/debugger/set-script-source-unchanged.js b/test/inspector/debugger/set-script-source-unchanged.js new file mode 100644 index 0000000000..bef4d8aaa1 --- /dev/null +++ b/test/inspector/debugger/set-script-source-unchanged.js @@ -0,0 +1,16 @@ +// Copyright 2020 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +let {session, contextGroup, Protocol} = + InspectorTest.start('Check that setScriptSource does not crash when source is unchanged'); + +let scriptSource = `function TestExpression() {}`; +contextGroup.addScript(scriptSource); + +(async function test() { + Protocol.Debugger.enable(); + const {params: {scriptId}} = await Protocol.Debugger.onceScriptParsed(); + await Protocol.Debugger.setScriptSource({scriptId, scriptSource}); + InspectorTest.completeTest(); +})();