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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_cidfont.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_font/cpdf_simplefont.h" 7 #include "core/fpdfapi/fpdf_font/cpdf_simplefont.h"
8 8
9 #include "core/fpdfapi/fpdf_font/font_int.h" 9 #include "core/fpdfapi/fpdf_font/font_int.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
12 #include "core/fxge/include/fx_freetype.h" 12 #include "core/fxge/include/fx_freetype.h"
13 #include "third_party/base/numerics/safe_math.h"
13 14
14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) { 15 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth)); 16 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth));
16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex)); 17 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex));
17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID)); 18 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID));
18 for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i) 19 for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i)
19 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1); 20 m_CharBBox[i] = FX_RECT(-1, -1, -1, -1);
20 } 21 }
21 22
22 CPDF_SimpleFont::~CPDF_SimpleFont() {} 23 CPDF_SimpleFont::~CPDF_SimpleFont() {}
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (width == 0) { 175 if (width == 0) {
175 width = m_CharWidth[i]; 176 width = m_CharWidth[i];
176 } else if (width != m_CharWidth[i]) { 177 } else if (width != m_CharWidth[i]) {
177 break; 178 break;
178 } 179 }
179 } 180 }
180 if (i == 256 && width) { 181 if (i == 256 && width) {
181 m_Flags |= PDFFONT_FIXEDPITCH; 182 m_Flags |= PDFFONT_FIXEDPITCH;
182 } 183 }
183 } 184 }
184 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); 185 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV);
185 m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags, weight, m_ItalicAngle, 186 if (m_StemV < 140)
187 safeStemV *= 5;
188 else
189 safeStemV = safeStemV * 4 + 140;
190 m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags,
191 safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle,
186 0); 192 0);
187 } 193 }
188 194
189 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { 195 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const {
190 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && 196 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN &&
191 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && 197 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
192 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; 198 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS;
193 } 199 }
194 200
195 CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(uint32_t charcode) const { 201 CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(uint32_t charcode) const {
196 CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode); 202 CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode);
197 if (!unicode.IsEmpty()) 203 if (!unicode.IsEmpty())
198 return unicode; 204 return unicode;
199 FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode); 205 FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode);
200 if (ret == 0) 206 if (ret == 0)
201 return CFX_WideString(); 207 return CFX_WideString();
202 return ret; 208 return ret;
203 } 209 }
204 210
205 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { 211 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const {
206 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); 212 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode);
207 if (ret) 213 if (ret)
208 return ret; 214 return ret;
209 return m_Encoding.CharCodeFromUnicode(unicode); 215 return m_Encoding.CharCodeFromUnicode(unicode);
210 } 216 }
OLDNEW
« no previous file with comments | « 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