diff options
author | Nico Weber <thakis@chromium.org> | 2023-05-01 09:47:28 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-04 15:39:34 +0200 |
commit | 2abe62adfa7024c85f771cb0bfec9be902221a84 (patch) | |
tree | c4bc3aeff2645652f70ce0357b84e71a5f4ebcc8 /Userland | |
parent | 3811be2f7c8169a4ddf973f9bb6cf3c44265d4db (diff) | |
download | serenity-2abe62adfa7024c85f771cb0bfec9be902221a84.zip |
LibWeb: Don't divide by 0 in DOMMatrix::invert_self()
We'd only check is_invertible() after calling inverse(), which would
do a divide-by-0 for non-invertible matrices.
Less ambitious version of #18593.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Geometry/DOMMatrix.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Geometry/DOMMatrix.cpp b/Userland/Libraries/LibWeb/Geometry/DOMMatrix.cpp index 94426f3465..345f11753a 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMMatrix.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMMatrix.cpp @@ -252,11 +252,14 @@ void DOMMatrix::set_f(double value) // https://drafts.fxtf.org/geometry/#dom-dommatrix-invertself JS::NonnullGCPtr<DOMMatrix> DOMMatrix::invert_self() { + bool is_invertible = m_matrix.is_invertible(); + // 1. Invert the current matrix. - m_matrix = m_matrix.inverse(); + if (is_invertible) + m_matrix = m_matrix.inverse(); // 2. If the current matrix is not invertible set all attributes to NaN and set is 2D to false. - if (!m_matrix.is_invertible()) { + if (!is_invertible) { for (u8 i = 0; i < 4; i++) { for (u8 j = 0; j < 4; j++) m_matrix.elements()[i][j] = NAN; |