tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 569552b3a36058798b33a0e5660748c6242bddc9
parent 2da8eb3289c7d7e4f44fbf20c37c7abb41a0c2d9
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Wed,  5 Nov 2025 22:10:53 +0000

Bug 1997351 - More explicitly deal with singular matrices in getCTM and getScreenCTM. r=jrmuizel

This is much like bug 1992972, but a bit more general.

The issue in this case is that GetViewBoxTransform() is singular,
because of the zero viewport height:

  https://searchfox.org/firefox-main/rev/cb52781342cc905eda923d009fc0b678f3a8c8c6/dom/svg/SVGViewportElement.cpp#162-164

Returning an identity matrix there seems a bit sketchy since it is used
in intermediate computations. Instead, deal with singular transforms at
the end of the process.

Differential Revision: https://phabricator.services.mozilla.com/D271409

Diffstat:
Mdom/svg/SVGGraphicsElement.cpp | 6++++++
Atesting/web-platform/tests/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html | 28++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/dom/svg/SVGGraphicsElement.cpp b/dom/svg/SVGGraphicsElement.cpp @@ -121,6 +121,9 @@ already_AddRefed<SVGMatrix> SVGGraphicsElement::GetCTM() { currentDoc->FlushPendingNotifications(FlushType::Layout); } gfx::Matrix m = SVGContentUtils::GetCTM(this); + if (m.IsSingular()) { + m = {}; + } return do_AddRef(new SVGMatrix(ThebesMatrix(m))); } @@ -130,6 +133,9 @@ already_AddRefed<SVGMatrix> SVGGraphicsElement::GetScreenCTM() { currentDoc->FlushPendingNotifications(FlushType::Layout); } gfx::Matrix m = SVGContentUtils::GetScreenCTM(this); + if (m.IsSingular()) { + m = {}; + } return do_AddRef(new SVGMatrix(ThebesMatrix(m))); } diff --git a/testing/web-platform/tests/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html b/testing/web-platform/tests/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>SVGGraphicsElement.getCTM and co with empty viewbox</title> +<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez"> +<link rel="author" href="https://mozilla.com" title="Mozilla"> +<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1997351"> +<link rel="help" href="https://svgwg.org/svg2-draft/types.html#InterfaceSVGGraphicsElement" /> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="container" style="width: 500px; height: 0px;"> + <svg width="100%" height="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> + <defs></defs> + <g class="viewport"> + </g> + </svg> +</div> +<script> + function assert_identity(m, prefix) { + assert_equals(m.a, 1, prefix + "a"); + assert_equals(m.d, 1, prefix + "d"); + for (let member of ["b", "c", "e", "f"]) { + assert_equals(m[member], 0, prefix + member); + } + } + test(function () { + assert_identity(document.querySelector(".viewport").getCTM(), "getCTM: "); + assert_identity(document.querySelector(".viewport").getScreenCTM(), "getScreenCTM: "); + }); +</script>