From 6dbb97510837bfcdec2fe061e860f67d0a42ae67 Mon Sep 17 00:00:00 2001 From: Eden Chuang Date: Fri, 25 Jul 2025 19:02:19 +0000 Subject: [PATCH] Bug 1968427 - Adding a null checking on WorkerPrivate::GlobalScope() in ServiceWorkerOpRunnable. a=diannaS WorkerPrivate's GlobalScope is created during CompileScriptRunnable::WorkerRun. However, the creation could fail when there is an OOM issue during the WebIDL bindings. Although the Worker will start the shutdown as soon as possible, there is still a chance that some WorkerRunnable had already been dispatched to the Worker. And there is no guarantee that there is a GlobalScope for the WorkerRunnable. Unfortunately, WorkerRunnable should check the GlobalScope existence by itself, because not every WorkerRunnable needs the GlobalScope to perform its functionality. This patch only does the null checking for the ServiceWorkerOpRunnable, since ServiceWorkerOpRunnable are supposed to dispatching an event to the corresponding ServiceWorkerGlobalScope. Original Revision: https://phabricator.services.mozilla.com/D254659 Differential Revision: https://phabricator.services.mozilla.com/D258725 --- dom/serviceworkers/ServiceWorkerOp.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dom/serviceworkers/ServiceWorkerOp.cpp b/dom/serviceworkers/ServiceWorkerOp.cpp index 9f7157e396f0..c57fd7fe2a7e 100644 --- a/dom/serviceworkers/ServiceWorkerOp.cpp +++ b/dom/serviceworkers/ServiceWorkerOp.cpp @@ -303,7 +303,10 @@ class ServiceWorkerOp::ServiceWorkerOpRunnable final MOZ_ASSERT(aWorkerPrivate->IsServiceWorker()); MOZ_ASSERT(mOwner); - if (aWorkerPrivate->GlobalScope()->IsDying()) { + // GlobalScope could be nullptr here that OOM issue causes GlobalScope + // creation fail. + if (!aWorkerPrivate->GlobalScope() || + aWorkerPrivate->GlobalScope()->IsDying()) { Unused << Cancel(); return true; }