Avoid loose bounds for invalid char codes
The current loose bounds computation assumes that the
CharInfo::char_code_ is valid. When the char code isn't valid the loose
bounds width will be zero.
In addition, the /ActualText kPiece currently attempt to store a valid
char code. However, this is incorrect as the text did not originate from
any char code. An incorrect char code could lead to the loose bounds
being calculated from a completely different glyph than that which was
used for drawing.
Bug: 42271607
Change-Id: Ie2d2d41287322f3aa3b28192d72f3a8301577d91
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/133370
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index cbb2b40..204def4 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -284,7 +284,8 @@
const CPDF_TextObject* text_object = charinfo.text_object();
float font_size = GetFontSize(text_object);
- if (text_object && !FXSYS_IsFloatZero(font_size)) {
+ if (text_object && !FXSYS_IsFloatZero(font_size) &&
+ charinfo.char_code() != CPDF_Font::kInvalidCharCode) {
RetainPtr<CPDF_Font> font = text_object->GetFont();
bool is_vert_writing = font->IsVertWriting();
if (is_vert_writing && font->IsCIDFont()) {
@@ -1038,7 +1039,7 @@
char_box.Translate(k * step, 0);
temp_text_buf_.AppendChar(wChar);
temp_char_list_.push_back(
- CharInfo(CharType::kPiece, font->CharCodeFromUnicode(wChar), wChar,
+ CharInfo(CharType::kPiece, CPDF_Font::kInvalidCharCode, wChar,
pTextObj->GetPos(), char_box, matrix, pTextObj));
}
}