Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Unified Diff: core/fpdfapi/fpdf_font/cpdf_simplefont.cpp

Issue 2293633002: Guard against overflow when calculating font weight. (Closed)
Patch Set: review feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
diff --git a/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp b/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
index 62d6959062ee2b3f353cccc1720326e32e839a52..a570bcd8b1c9de90a45262e29b7bfd1e319bb821 100644
--- a/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
@@ -10,6 +10,7 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fxge/include/fx_freetype.h"
+#include "third_party/base/numerics/safe_math.h"
CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth));
@@ -181,9 +182,13 @@ void CPDF_SimpleFont::LoadSubstFont() {
m_Flags |= PDFFONT_FIXEDPITCH;
}
}
- int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140);
- m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags, weight, m_ItalicAngle,
- 0);
+ pdfium::base::CheckedNumeric<int> safeStemV(m_StemV);
+ if (m_StemV < 140)
+ safeStemV *= 5;
+ else
+ safeStemV = safeStemV * 5 + 140;
Wei Li 2016/08/29 23:05:48 Shouldn't multiple 4 here?
dsinclair 2016/08/30 14:26:39 Doh. Good catch, thanks.
+ m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags,
+ safeStemV.ValueOrDefault(140), m_ItalicAngle, 0);
Wei Li 2016/08/29 23:05:48 Maybe the default value should be FXFONT_FW_NORMAL
dsinclair 2016/08/30 14:26:39 Went with normal, thanks for pointing it out.
}
FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const {
« core/fpdfapi/fpdf_font/cpdf_cidfont.cpp ('K') | « core/fpdfapi/fpdf_font/cpdf_cidfont.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698