fix: stop Parse QR Code from participating in Magic (#2610) (#2613)

This commit is contained in:
Sanjay Santhanam 2026-07-25 01:08:18 -07:00 committed by GitHub
parent be42a3b9c8
commit c56dd23358
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 9 deletions

View File

@ -33,15 +33,11 @@ class ParseQRCode extends Operation {
value: false, value: false,
}, },
]; ];
this.checks = [ // No Magic checks: detecting a QR code in arbitrary image data requires
{ // actually attempting to parse one, which is expensive and produces
pattern: // spurious "Could not read a QR code from the image" log messages for
"^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)", // any image input via Magic. Users can add Parse QR Code manually when
flags: "", // they know the image contains a QR code. See issue #2610.
args: [false],
useful: true,
},
];
} }
/** /**

View File

@ -27,6 +27,7 @@ import "./tests/Categories.mjs";
import "./tests/ToHTMLEntity.mjs"; import "./tests/ToHTMLEntity.mjs";
import "./tests/lib/BigIntUtils.mjs"; import "./tests/lib/BigIntUtils.mjs";
import "./tests/lib/ChartsProtocolPrototypePollution.mjs"; import "./tests/lib/ChartsProtocolPrototypePollution.mjs";
import "./tests/ParseQRCode.mjs";
const testStatus = { const testStatus = {
allTestsPassing: true, allTestsPassing: true,

View File

@ -0,0 +1,35 @@
/**
* ParseQRCode API tests.
*
* @author Sanjays2402
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
import OperationConfig from "../../../src/core/config/OperationConfig.json" with { type: "json" };
import it from "../assertionHandler.mjs";
import assert from "assert";
TestRegister.addApiTests([
/*
* Regression test for #2610.
*
* Parse QR Code used to declare a `checks` regex that matched any JPEG,
* PNG, GIF, WEBP or BMP magic bytes. Magic aggregates every operation
* with a `checks` property, so any image input ran through a full QR
* parse attempt, which in turn emitted a "Could not read a QR code from
* the image" warning to the browser console for every image. There is
* no cheap way to detect a QR code without attempting a full parse, so
* Parse QR Code must not participate in Magic; users can add it
* manually when they know an image contains a QR code.
*/
it("Parse QR Code: must not participate in Magic (#2610)", () => {
const op = OperationConfig["Parse QR Code"];
assert(op, "Parse QR Code operation is missing from OperationConfig");
assert(
!op.checks || op.checks.length === 0,
"Parse QR Code must not declare `checks`; otherwise Magic will run a " +
"QR parse on every image and spam the console (see issue #2610)."
);
}),
]);