From 5101088eabc0f5acd35c3123d9e02dd9c058f9af Mon Sep 17 00:00:00 2001 From: Samuel Ugochukwu Date: Tue, 7 Jan 2025 18:31:52 +0100 Subject: [PATCH] Fix undefined behavior caused by a null clip path element #209 --- source/svgelement.cpp | 4 ++-- source/svggeometryelement.cpp | 2 +- source/svggeometryelement.h | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/svgelement.cpp b/source/svgelement.cpp index c4b30ed..20a08e0 100644 --- a/source/svgelement.cpp +++ b/source/svgelement.cpp @@ -1041,7 +1041,7 @@ void SVGClipPathElement::applyClipPath(SVGRenderState& state) const shapeElement = toSVGGeometryElement(element->firstChild()); } - if(shapeElement == nullptr || shapeElement->isDisplayNone() || shapeElement->isVisibilityHidden()) + if(shapeElement == nullptr || !shapeElement->isRenderable()) continue; state->clipPath(shapeElement->path(), shapeElement->clip_rule(), clipTransform * shapeElement->localTransform()); return; @@ -1070,7 +1070,7 @@ bool SVGClipPathElement::requiresMasking() const shapeElement = toSVGGeometryElement(element->firstChild()); } - if(shapeElement == nullptr || shapeElement->isDisplayNone() || shapeElement->isVisibilityHidden()) + if(shapeElement == nullptr || !shapeElement->isRenderable()) continue; if(prevShapeElement || shapeElement->clipper()) return true; diff --git a/source/svggeometryelement.cpp b/source/svggeometryelement.cpp index 14819d5..caa592e 100644 --- a/source/svggeometryelement.cpp +++ b/source/svggeometryelement.cpp @@ -138,7 +138,7 @@ void SVGGeometryElement::updateMarkerPositions(SVGMarkerPositionList& positions, void SVGGeometryElement::render(SVGRenderState& state) const { - if(m_path.isNull() || isVisibilityHidden() || isDisplayNone()) + if(!isRenderable()) return; SVGBlendInfo blendInfo(this); SVGRenderState newState(this, state, localTransform()); diff --git a/source/svggeometryelement.h b/source/svggeometryelement.h index 03508f6..101cfd0 100644 --- a/source/svggeometryelement.h +++ b/source/svggeometryelement.h @@ -36,6 +36,8 @@ class SVGGeometryElement : public SVGGraphicsElement { Rect strokeBoundingBox() const override; void layoutElement(const SVGLayoutState& state) override; + bool isRenderable() const { return !m_path.isNull() && !isDisplayNone() && !isVisibilityHidden(); } + FillRule fill_rule() const { return m_fill_rule; } FillRule clip_rule() const { return m_clip_rule; }