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

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

Issue 2293633002: Guard against overflow when calculating font weight. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
npm 2016/08/29 19:23:39 Maybe you can also do something similar in CPDF_CI
dsinclair 2016/08/29 19:40:55 Done.
+ if (m_StemV < 140)
+ safeStemV *= 5;
+ else
+ safeStemV = safeStemV * 5 + 140;
+ m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags,
+ safeStemV.ValueOrDefault(140), m_ItalicAngle, 0);
dsinclair 2016/08/29 19:15:43 I made up 140 in here as it seemed to be the numbe
}
FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698