1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 23:42:39 +01:00

Fix potential infinite async loop

Related issue:
https://bugzilla.mozilla.org/show_bug.cgi?id=1929326

As identified by @Rob--W:
https://bugzilla.mozilla.org/show_bug.cgi?id=1929326#c9

Truncated or otherwise corrupted asset content in extension storage
could lead to infinite async loop causing high CPU usage in uBO and
its workers.

Likely related to the issue of the asset content returned as
`undefined`:
652f178787/src/js/cachestorage.js (L98)
This commit is contained in:
Raymond Hill 2024-11-11 15:08:10 -05:00
parent 15dae359f7
commit 335d947c10
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -19,18 +19,15 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
'use strict'; import * as sfp from './static-filtering-parser.js';
/******************************************************************************/
import µb from './background.js';
import { broadcast } from './broadcast.js'; import { broadcast } from './broadcast.js';
import cacheStorage from './cachestorage.js'; import cacheStorage from './cachestorage.js';
import { ubolog } from './console.js';
import { i18n$ } from './i18n.js'; import { i18n$ } from './i18n.js';
import logger from './logger.js'; import logger from './logger.js';
import * as sfp from './static-filtering-parser.js'; import { orphanizeString } from './text-utils.js';
import { orphanizeString, } from './text-utils.js'; import { ubolog } from './console.js';
import µb from './background.js';
/******************************************************************************/ /******************************************************************************/
@ -50,6 +47,9 @@ let remoteServerFriendly = false;
/******************************************************************************/ /******************************************************************************/
const hasOwnProperty = (o, p) =>
Object.prototype.hasOwnProperty.call(o, p);
const stringIsNotEmpty = s => typeof s === 'string' && s !== ''; const stringIsNotEmpty = s => typeof s === 'string' && s !== '';
const parseExpires = s => { const parseExpires = s => {
@ -107,8 +107,8 @@ const resourceTimeFromXhr = xhr => {
const resourceTimeFromParts = (parts, time) => { const resourceTimeFromParts = (parts, time) => {
const goodParts = parts.filter(part => typeof part === 'object'); const goodParts = parts.filter(part => typeof part === 'object');
return goodParts.reduce((acc, part) => return goodParts.reduce(
((part.resourceTime || 0) > acc ? part.resourceTime : acc), (acc, part) => ((part.resourceTime || 0) > acc ? part.resourceTime : acc),
time time
); );
}; };
@ -246,6 +246,7 @@ const fireNotification = function(topic, details) {
assets.fetch = function(url, options = {}) { assets.fetch = function(url, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Start of executor // Start of executor
/* eslint-disable indent */
const timeoutAfter = µb.hiddenSettings.assetFetchTimeout || 30; const timeoutAfter = µb.hiddenSettings.assetFetchTimeout || 30;
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
@ -322,6 +323,7 @@ assets.fetch = function(url, options = {}) {
onErrorEvent.call(xhr); onErrorEvent.call(xhr);
} }
/* eslint-enable indent */
// End of executor // End of executor
}); });
}; };
@ -733,7 +735,7 @@ async function assetCacheRead(assetKey, updateReadTime = false) {
} }
if ( bin instanceof Object === false ) { return reportBack(''); } if ( bin instanceof Object === false ) { return reportBack(''); }
if ( bin.hasOwnProperty(internalKey) === false ) { return reportBack(''); } if ( hasOwnProperty(bin, internalKey) === false ) { return reportBack(''); }
const entry = assetCacheRegistry[assetKey]; const entry = assetCacheRegistry[assetKey];
if ( entry === undefined ) { return reportBack(''); } if ( entry === undefined ) { return reportBack(''); }
@ -1277,7 +1279,9 @@ async function diffUpdater() {
if ( data.status === 'needtext' ) { if ( data.status === 'needtext' ) {
ubolog('Diff updater: need text for', data.assetKey); ubolog('Diff updater: need text for', data.assetKey);
assetCacheRead(data.assetKey).then(result => { assetCacheRead(data.assetKey).then(result => {
data.text = result.content; // https://bugzilla.mozilla.org/show_bug.cgi?id=1929326#c9
// Must never be set to undefined!
data.text = result.content || '';
data.status = undefined; data.status = undefined;
checkAndCorrectDiffPath(data); checkAndCorrectDiffPath(data);
bc.postMessage(data); bc.postMessage(data);