[svg] Fix null text context crash
The input may contain invalid text constructs lacking a root <text> node
e.g. <svg><tspan>foo</tspan></svg>
Since we don't perform content model validation at the moment and text
contexts are only instantiated for root nodes, we must guard against
this case at render time.
Bug: oss-fuzz:29558
Change-Id: I7e39c1c4048900ce5becb3549802dc66bb1d242b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353711
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
diff --git a/modules/svg/src/SkSVGText.cpp b/modules/svg/src/SkSVGText.cpp
index 37f604f..b7398d7 100644
--- a/modules/svg/src/SkSVGText.cpp
+++ b/modules/svg/src/SkSVGText.cpp
@@ -506,6 +506,11 @@
void SkSVGTextContainer::onRenderText(const SkSVGRenderContext& ctx, SkSVGTextContext* tctx,
SkSVGXmlSpace) const {
+ if (!tctx) {
+ // No text context => missing top-level <text> node.
+ return;
+ }
+
const SkSVGTextContext::ScopedPosResolver resolver(*this, ctx.lengthContext(), tctx);
for (const auto& frag : fChildren) {