From cf96b626f5e14611af5709a90c2509c5bd06b224 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 11 Nov 2024 15:08:10 -0500 Subject: [PATCH 1/9] 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`: https://github.com/gorhill/uBlock/blob/652f1787878ba434c3a65287afcd84082c409397/src/js/cachestorage.js#L98 --- src/js/assets.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/js/assets.js b/src/js/assets.js index e1bc4e616a3ea..4f02700f8c46e 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -19,18 +19,15 @@ 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 cacheStorage from './cachestorage.js'; -import { ubolog } from './console.js'; import { i18n$ } from './i18n.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 parseExpires = s => { @@ -107,8 +107,8 @@ const resourceTimeFromXhr = xhr => { const resourceTimeFromParts = (parts, time) => { const goodParts = parts.filter(part => typeof part === 'object'); - return goodParts.reduce((acc, part) => - ((part.resourceTime || 0) > acc ? part.resourceTime : acc), + return goodParts.reduce( + (acc, part) => ((part.resourceTime || 0) > acc ? part.resourceTime : acc), time ); }; @@ -246,6 +246,7 @@ const fireNotification = function(topic, details) { assets.fetch = function(url, options = {}) { return new Promise((resolve, reject) => { // Start of executor + /* eslint-disable indent */ const timeoutAfter = µb.hiddenSettings.assetFetchTimeout || 30; const xhr = new XMLHttpRequest(); @@ -322,6 +323,7 @@ assets.fetch = function(url, options = {}) { onErrorEvent.call(xhr); } + /* eslint-enable indent */ // End of executor }); }; @@ -733,7 +735,7 @@ async function assetCacheRead(assetKey, updateReadTime = false) { } 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]; if ( entry === undefined ) { return reportBack(''); } @@ -1277,7 +1279,9 @@ async function diffUpdater() { if ( data.status === 'needtext' ) { ubolog('Diff updater: need text for', data.assetKey); 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; checkAndCorrectDiffPath(data); bc.postMessage(data); From d82c6c8969255e65484756195db02dc8bed08b44 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 14 Nov 2024 10:32:15 -0500 Subject: [PATCH 2/9] Better handle unexpected conditions when deserializing For example, when deserialzing from corrupted storage. --- src/js/s14e-serializer.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/js/s14e-serializer.js b/src/js/s14e-serializer.js index 98f0d9cc20982..8b1850f136fe9 100644 --- a/src/js/s14e-serializer.js +++ b/src/js/s14e-serializer.js @@ -1097,32 +1097,36 @@ export const serialize = (data, options = {}) => { return ratio <= 0.85 ? t : s; }; -export const deserialize = s => { - if ( s.startsWith(MAGICLZ4PREFIX) ) { - refCounter = 1; - readStr = s; - readEnd = s.length; - readPtr = MAGICLZ4PREFIX.length; - const lz4 = _deserialize(); - readRefs.clear(); - readStr = ''; - const lz4Util = new LZ4BlockJS(); - const uint8ArrayAfter = lz4Util.decode(lz4.data, 0, lz4.size); - s = textCodec.decode(new Uint8Array(uint8ArrayAfter)); - } - if ( s.startsWith(MAGICPREFIX) === false ) { return; } +const deserializeById = (blockid, s) => { refCounter = 1; readStr = s; readEnd = s.length; - readPtr = MAGICPREFIX.length; + readPtr = blockid.length; const data = _deserialize(); readRefs.clear(); readStr = ''; - uint8Input = null; if ( readPtr === FAILMARK ) { return; } return data; }; +export const deserialize = s => { + if ( s.startsWith(MAGICLZ4PREFIX) ) { + const lz4 = deserializeById(MAGICLZ4PREFIX, s); + if ( lz4 ) { + const lz4Util = new LZ4BlockJS(); + const uint8ArrayAfter = lz4Util.decode(lz4.data, 0, lz4.size); + if ( uint8ArrayAfter ) { + s = textCodec.decode(new Uint8Array(uint8ArrayAfter)); + } + } + } + const data = s.startsWith(MAGICPREFIX) + ? deserializeById(MAGICPREFIX, s) + : undefined; + uint8Input = null; + return data; +}; + export const isSerialized = s => typeof s === 'string' && (s.startsWith(MAGICLZ4PREFIX) || s.startsWith(MAGICPREFIX)); From 1e999924f26d96ba7fe3bfbee52c727dc900928b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 19 Nov 2024 09:42:51 -0500 Subject: [PATCH 3/9] New revision for stable release --- dist/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/version b/dist/version index 84c7d0bad2dae..658b056b13096 100644 --- a/dist/version +++ b/dist/version @@ -1 +1 @@ -1.61.0 \ No newline at end of file +1.61.2 \ No newline at end of file From 3b7012313879ea13d26fcdcb826e206801bd6403 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 8 Nov 2024 12:07:30 -0500 Subject: [PATCH 4/9] Address workflow warnings --- .github/workflows/main.yml | 57 +++++++++----------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ce7af1212a4f..f70f3fbe57096 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,12 @@ jobs: - name: Clone uAssets run: | tools/pull-assets.sh + - name: Build MV2 packages + run: | + tools/make-chromium.sh ${{ steps.release_info.outputs.VERSION }} + tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }} + tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }} + tools/make-npm.sh ${{ steps.release_info.outputs.VERSION }} # https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html - name: Get release information id: release_info @@ -37,54 +43,17 @@ jobs: sed -e 's/%version%/${{ steps.release_info.outputs.VERSION }}/g' RELEASE.HEAD.md >> release.body.txt - name: Create GitHub release id: create_release - uses: actions/create-release@v1 + uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ github.token }} with: tag_name: ${{ steps.release_info.outputs.VERSION }} - release_name: ${{ steps.release_info.outputs.VERSION }} + name: ${{ steps.release_info.outputs.VERSION }} draft: true prerelease: true body_path: release.body.txt - - name: Build MV2 packages - run: | - tools/make-chromium.sh ${{ steps.release_info.outputs.VERSION }} - tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }} - tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }} - tools/make-npm.sh ${{ steps.release_info.outputs.VERSION }} - - name: Upload Chromium package - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.chromium.zip - asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.chromium.zip - asset_content_type: application/octet-stream - - name: Upload Firefox package - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.firefox.xpi - asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.firefox.xpi - asset_content_type: application/octet-stream - - name: Upload Thunderbird package - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.thunderbird.xpi - asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.thunderbird.xpi - asset_content_type: application/octet-stream - - name: Upload NodeJS package - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz - asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz - asset_content_type: application/octet-stream + files: | + dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.chromium.zip + dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.firefox.xpi + dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.thunderbird.xpi + dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz From f18a9a22bf71946cbceb5a324be586d0df4bc8e4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 8 Nov 2024 12:17:27 -0500 Subject: [PATCH 5/9] Fix more workflow warnings; fix steps order --- .github/workflows/main.yml | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f70f3fbe57096..1d34c0242d012 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,9 +7,6 @@ on: permissions: contents: read -# I used the following project as template to get started: -# https://github.com/dessant/search-by-image/blob/master/.github/workflows/ci.yml - jobs: build: permissions: @@ -25,35 +22,33 @@ jobs: - name: Clone uAssets run: | tools/pull-assets.sh - - name: Build MV2 packages - run: | - tools/make-chromium.sh ${{ steps.release_info.outputs.VERSION }} - tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }} - tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }} - tools/make-npm.sh ${{ steps.release_info.outputs.VERSION }} - # https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html - name: Get release information - id: release_info run: | - echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + - name: Build MV2 packages + run: | + tools/make-chromium.sh ${{ env.VERSION }} + tools/make-firefox.sh ${{ env.VERSION }} + tools/make-thunderbird.sh ${{ env.VERSION }} + tools/make-npm.sh ${{ env.VERSION }} - name: Assemble release notes run: | > release.body.txt grep -m1 -B10000 -- "----------" CHANGELOG.md >> release.body.txt - sed -e 's/%version%/${{ steps.release_info.outputs.VERSION }}/g' RELEASE.HEAD.md >> release.body.txt + sed -e 's/%version%/${{ env.VERSION }}/g' RELEASE.HEAD.md >> release.body.txt - name: Create GitHub release id: create_release uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ github.token }} with: - tag_name: ${{ steps.release_info.outputs.VERSION }} - name: ${{ steps.release_info.outputs.VERSION }} + tag_name: ${{ env.VERSION }} + name: ${{ env.VERSION }} draft: true prerelease: true body_path: release.body.txt files: | - dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.chromium.zip - dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.firefox.xpi - dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.thunderbird.xpi - dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.npm.tgz + dist/build/uBlock0_${{ env.VERSION }}.chromium.zip + dist/build/uBlock0_${{ env.VERSION }}.firefox.xpi + dist/build/uBlock0_${{ env.VERSION }}.thunderbird.xpi + dist/build/uBlock0_${{ env.VERSION }}.npm.tgz From 5b14018c77f6452fbce826a80d3a86fcc14d26d6 Mon Sep 17 00:00:00 2001 From: Alberto Harres Date: Tue, 17 Dec 2024 00:02:00 +0100 Subject: [PATCH 6/9] add pull-assets to the build script --- tools/copy-common-files.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/copy-common-files.sh b/tools/copy-common-files.sh index 215aad8fc10bd..c639c7bd0fdbd 100644 --- a/tools/copy-common-files.sh +++ b/tools/copy-common-files.sh @@ -5,6 +5,8 @@ DES=$1 UBLOCK=$( cat dist/version ) # ADN:ublock-version +bash ./tools/pull-assets.sh # ADN + bash ./tools/make-assets.sh $DES bash ./tools/make-locales.sh $DES From 73e2e14dcfdc4da7ca62d99acb4b52f15de12e77 Mon Sep 17 00:00:00 2001 From: Alberto Harres Date: Fri, 20 Dec 2024 15:52:23 +0100 Subject: [PATCH 7/9] fix merge import error --- src/js/assets.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/js/assets.js b/src/js/assets.js index 476e600fcfc68..a6fe4382c0a20 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -32,8 +32,6 @@ import { adnlog } from './console.js'; import { i18n$ } from './i18n.js'; import logger from './logger.js'; import { orphanizeString } from './text-utils.js'; -import { adnlog } from './console.js'; -import µb from './background.js'; /******************************************************************************/ From 8fffff7ae4314ea90861ad2044d1c97877777acf Mon Sep 17 00:00:00 2001 From: Alberto Harres Date: Fri, 20 Dec 2024 15:58:26 +0100 Subject: [PATCH 8/9] minor vault fix #2577 --- src/css/vault.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/css/vault.css b/src/css/vault.css index 5039d1d0140a8..8725f954ac8ad 100755 --- a/src/css/vault.css +++ b/src/css/vault.css @@ -22,7 +22,7 @@ body { font-stretch: 47.5%; font-variation-settings: "opsz" 48, "slnt" 0, "GRAD" 0, "XTRA" 468, "YOPQ" 79, "YTAS" 750, "YTDE" -203, "YTFI" 738, "YTLC" 514, "YTUC" 712; z-index: 50; - margin-bottom: 30px; + margin-bottom: 40px; cursor: default; user-select:none; width:270px; @@ -329,6 +329,7 @@ div.tooltip { position: relative; display: inline-block; z-index: 100; + width: 700px; font-size: 16px; font-family: bebas_neue,roboto_flex,noto_sans,sans-serif; font-stretch: 47.5%; From ce7e2ec80f85637fb5878bbc8b54f3c97a906a81 Mon Sep 17 00:00:00 2001 From: Alberto Harres Date: Fri, 20 Dec 2024 16:14:02 +0100 Subject: [PATCH 9/9] fix version number --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4366d048a04cf..02ed97ef72d79 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "version": "3.24.3.1", + "version": "3.23.3.1", "key": "ilkggpgmkemaniponkfgnkonpajankkm", "author": "Daniel C. Howe", "background": {