From e28b36585ef8a862061f19a96f9e7ab6c5fbb944 Mon Sep 17 00:00:00 2001 From: David Reinecke <6206278+dreinecke@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:47:52 +0000 Subject: [PATCH] Decode base64 without the deprecated Qt.atob (C-082) Qt 6.12 deprecates the string form of Qt.atob. Mail's base64 decoding now always uses its own JavaScript decoder, which its tests already cover, and importing an HTML signature uses it too. A file too large to ever fit in a signature is refused before it is decoded, and a check keeps Qt.atob out of the app's code. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FLvc6ysxJTzP72yY4diHA3 --- ui/components/SettingsPage.qml | 11 ++++++++++- ui/message/Message.js | 8 ++------ ui/tests/qml/tst_message_base64.qml | 4 +++- .../qml/tst_signature_import_lifecycle.qml | 19 +++++++++++++++++++ ui/tests/test_message.js | 19 +++++++++++++++++++ 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/ui/components/SettingsPage.qml b/ui/components/SettingsPage.qml index d9510d039..b2eeec5b9 100644 --- a/ui/components/SettingsPage.qml +++ b/ui/components/SettingsPage.qml @@ -5,6 +5,7 @@ import Quickshell.Io import qs.Commons import qs.Ui import "../message/Direction.js" as Direction +import "../message/Message.js" as Message import "../settings/Appearance.js" as Appearance import "../message/Html.js" as Html @@ -180,9 +181,17 @@ Column { importFailed = true return } + // Invariant: The engine refuses HTML over 256 K UTF-16 units, and a UTF-8 byte yields at most one unit for every + // three bytes, so a larger file is refused here before the JavaScript decoder spends time on it. + if (kind === "html" && Number(result.size || String(result.data || "").length * 3 / 4) > 3 * 256 * 1024) { + importing = false + importNote = "That file is too large for a signature" + importFailed = true + return + } var accountId = importingAccountId service.backend.call("message.signatureImport", { kind: kind, - data: kind === "html" ? Qt.atob(String(result.data || "")) : String(result.data || "") + data: kind === "html" ? Message.decodeBase64Url(String(result.data || "")) : String(result.data || "") }, function(imported, error) { root.importing = false if (error || !imported) { diff --git a/ui/message/Message.js b/ui/message/Message.js index 415d0a6cb..a26d419d8 100644 --- a/ui/message/Message.js +++ b/ui/message/Message.js @@ -85,15 +85,11 @@ function bytesToLatin1(bytes) { return out } -// Invariant: Qt.atob returns decoded QString text; decoding it again as byte values corrupts non-ASCII text. +// Invariant: Decodes base64 or base64url bytes as UTF-8 in JavaScript, not with Qt.atob, whose string form Qt has +// deprecated; QML and the Node tests then share one decoder, and malformed bytes fall back as bytesToUtf8 says. function decodeBase64Url(text) { var input = String(text || "") if (input === "") return "" - if (typeof Qt !== "undefined" && typeof Qt.atob === "function") { - try { - return Qt.atob(input.replace(/-/g, "+").replace(/_/g, "/")) - } catch (parseError) {} - } return bytesToUtf8(base64ToBytes(input)) } diff --git a/ui/tests/qml/tst_message_base64.qml b/ui/tests/qml/tst_message_base64.qml index fb6751e5d..2a357b989 100644 --- a/ui/tests/qml/tst_message_base64.qml +++ b/ui/tests/qml/tst_message_base64.qml @@ -11,8 +11,10 @@ Item { - function test_qt_atob_result_is_not_decoded_a_second_time() { + function test_base64_decodes_utf8_text_once() { compare(Message.decodeBase64Url("QWxleCDDoCBsJ8OpY29sZQ=="), "Alex à l'école") + compare(Message.decodeBase64Url("8J+Ygg"), "\ud83d\ude02") + compare(Message.decodeBase64Url("PHA-w6k8L3A-"), "

é

") } function test_encoded_display_text_cannot_route_a_reply() { diff --git a/ui/tests/qml/tst_signature_import_lifecycle.qml b/ui/tests/qml/tst_signature_import_lifecycle.qml index 653dedcc6..e3a6903f2 100644 --- a/ui/tests/qml/tst_signature_import_lifecycle.qml +++ b/ui/tests/qml/tst_signature_import_lifecycle.qml @@ -125,6 +125,25 @@ Item { compare(page.importFailed, true) compare(page.importNote, "That image cannot be safely displayed") } + function test_html_import_sends_decoded_utf8_text() { + page.importSignature() + fakeService.pickerCallback({ok: true, paths: ["/synthetic/signature.html"]}) + fakeBackend.callback({ok: true, mimeType: "text/html", filename: "signature.html", size: 9, + data: "PHA+w6k8L3A+"}, null) + compare(fakeBackend.method, "message.signatureImport") + compare(fakeBackend.params.kind, "html") + compare(fakeBackend.params.data, "

\u00e9

") + } + function test_oversized_html_import_is_refused_before_decoding() { + page.importSignature() + fakeService.pickerCallback({ok: true, paths: ["/synthetic/signature.html"]}) + fakeBackend.callback({ok: true, mimeType: "text/html", filename: "signature.html", + size: 3 * 256 * 1024 + 1, data: "PHA+w6k8L3A+"}, null) + compare(fakeBackend.method, "attachment.read") + compare(page.importing, false) + compare(page.importFailed, true) + compare(page.importNote, "That file is too large for a signature") + } function test_picker_completion_keeps_the_original_account() { page.importSignature() page.selectSignatureAccount("b@example.net") diff --git a/ui/tests/test_message.js b/ui/tests/test_message.js index 694644c5f..92321055d 100644 --- a/ui/tests/test_message.js +++ b/ui/tests/test_message.js @@ -1235,4 +1235,23 @@ assert.strictEqual(message.composeBody("\n\n", ""), "") assert.strictEqual(message.draftFields({ replyTo: { email: "team@example.com" }, to: [] }, "x").replyTo, "team@example.com") assert.strictEqual(message.draftFields({ replyTo: { email: "" }, to: [] }, "x").replyTo, "") +// Invariant: production code decodes base64 in JavaScript; Qt has deprecated the string form of Qt.atob. +{ + const fs = require("fs") + const path = require("path") + const repository = path.join(__dirname, "..", "..") + const offenders = [] + const visit = directory => { + for (const entry of fs.readdirSync(directory, { withFileTypes: true })) { + const full = path.join(directory, entry.name) + if (entry.isDirectory()) { if (entry.name !== "tests") visit(full); continue } + if (!/\.(qml|js)$/.test(entry.name)) continue + if (/\bQt\.atob\s*\(/.test(fs.readFileSync(full, "utf8"))) offenders.push(path.relative(repository, full)) + } + } + visit(path.join(repository, "ui")) + visit(path.join(repository, "app", "qml")) + assert.deepStrictEqual(offenders, [], "Qt.atob is deprecated in Qt 6.12; decode with Message.decodeBase64Url") +} + console.log("test_message.js ok")