diff --git a/third_party/blink/renderer/core/layout/ng/inline/ng_paragraph_line_breaker.cc b/third_party/blink/renderer/core/layout/ng/inline/ng_paragraph_line_breaker.cc index 82264bda995053..b7c861e1f91ade 100644 --- a/third_party/blink/renderer/core/layout/ng/inline/ng_paragraph_line_breaker.cc +++ b/third_party/blink/renderer/core/layout/ng/inline/ng_paragraph_line_breaker.cc @@ -106,7 +106,15 @@ wtf_size_t EstimateNumLines(const String& text_content, const SimpleFontData* font, LayoutUnit available_width) { const float space_width = font->SpaceWidth(); + if (space_width <= 0) { + // Can't estimate without space glyph, go on to measure the actual value. + return 0; + } const wtf_size_t num_line_chars = available_width / space_width; + if (num_line_chars <= 0) { + // The width is too narrow, don't balance. + return std::numeric_limits::max(); + } return (text_content.length() + num_line_chars - 1) / num_line_chars; } diff --git a/third_party/blink/web_tests/external/wpt/css/css-text/white-space/text-wrap-balance-narrow-crash.html b/third_party/blink/web_tests/external/wpt/css/css-text/white-space/text-wrap-balance-narrow-crash.html new file mode 100644 index 00000000000000..dcc0d8773df6c7 --- /dev/null +++ b/third_party/blink/web_tests/external/wpt/css/css-text/white-space/text-wrap-balance-narrow-crash.html @@ -0,0 +1,2 @@ + +
A