Fix nullptr dereference in ParseStyles().
Recently, https://pdfium-review.googlesource.com/91938 incorrectly
refactored some font style parsing code. When the parsed result is not
available, the parsed style should have a default value.
Bug: chromium:1313008
Change-Id: I38de4c3f0bdcad6de0818419274d93ade4ac6375
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/92170
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index decd1fc..118b194 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -247,10 +247,15 @@
if ((i && !*is_style_available) || (!i && !style_result))
return true;
- if (style_result)
+ uint32_t parsed_style;
+ if (style_result) {
*is_style_available = true;
+ parsed_style = style_result->style;
+ } else {
+ parsed_style = FXFONT_NORMAL;
+ }
- if (FontStyleIsForceBold(style_result->style)) {
+ if (FontStyleIsForceBold(parsed_style)) {
// If we're already bold, then we're double bold, use special weight.
if (FontStyleIsForceBold(*style)) {
*weight = FXFONT_FW_BOLD_BOLD;
@@ -261,10 +266,9 @@
is_first_item = false;
}
- if (FontStyleIsItalic(style_result->style) &&
- FontStyleIsForceBold(style_result->style)) {
+ if (FontStyleIsItalic(parsed_style) && FontStyleIsForceBold(parsed_style)) {
*style |= FXFONT_ITALIC;
- } else if (FontStyleIsItalic(style_result->style)) {
+ } else if (FontStyleIsItalic(parsed_style)) {
if (!is_first_item)
return true;