From b6a960c96cfc9acb12684ac44d956be90f127995 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Sat, 24 Feb 2024 08:56:43 +0000 Subject: [PATCH] Bug 1880996 - Check for zero-length text in nsBidiPresUtils::ProcessSimpleRun. r=dholbert In the example here, failing to check for an empty string was resulting in lots of extra work to set up for drawing a shadow, etc., even though nothing ends up being rendered. Just bail out early if there's no text. Differential Revision: https://phabricator.services.mozilla.com/D202630 --- layout/base/nsBidiPresUtils.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/layout/base/nsBidiPresUtils.cpp b/layout/base/nsBidiPresUtils.cpp index ad085edbb12f..b1215972c243 100644 --- a/layout/base/nsBidiPresUtils.cpp +++ b/layout/base/nsBidiPresUtils.cpp @@ -2363,6 +2363,12 @@ void nsBidiPresUtils::ProcessSimpleRun(const char16_t* aText, size_t aLength, nsBidiPositionResolve* aPosResolve, int32_t aPosResolveCount, nscoord* aWidth) { + if (!aLength) { + if (aWidth) { + *aWidth = 0; + } + return; + } // Get bidi class from the first (or only) character. uint32_t ch = aText[0]; if (aLength > 1 && NS_IS_HIGH_SURROGATE(ch) &&