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

Side by Side Diff: core/fpdfapi/fpdf_font/fpdf_font.cpp

Issue 2393573002: Use FX_SAFE_UINT32 on CPDF_ToUnicodeMap::Load (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | 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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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/font_int.h" 7 #include "core/fpdfapi/fpdf_font/font_int.h"
8 8
9 #include "core/fpdfapi/cpdf_modulemgr.h" 9 #include "core/fpdfapi/cpdf_modulemgr.h"
10 #include "core/fpdfapi/fpdf_page/cpdf_form.h" 10 #include "core/fpdfapi/fpdf_page/cpdf_form.h"
11 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" 11 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h"
12 #include "core/fpdfapi/fpdf_page/pageint.h" 12 #include "core/fpdfapi/fpdf_page/pageint.h"
13 #include "core/fpdfapi/fpdf_parser/cpdf_array.h" 13 #include "core/fpdfapi/fpdf_parser/cpdf_array.h"
14 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" 14 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h"
15 #include "core/fpdfapi/fpdf_parser/cpdf_document.h" 15 #include "core/fpdfapi/fpdf_parser/cpdf_document.h"
16 #include "core/fpdfapi/fpdf_parser/cpdf_name.h" 16 #include "core/fpdfapi/fpdf_parser/cpdf_name.h"
17 #include "core/fpdfapi/fpdf_parser/cpdf_number.h" 17 #include "core/fpdfapi/fpdf_parser/cpdf_number.h"
18 #include "core/fpdfapi/fpdf_parser/cpdf_simple_parser.h" 18 #include "core/fpdfapi/fpdf_parser/cpdf_simple_parser.h"
19 #include "core/fpdfapi/fpdf_parser/cpdf_stream_acc.h" 19 #include "core/fpdfapi/fpdf_parser/cpdf_stream_acc.h"
20 #include "core/fxcrt/fx_ext.h" 20 #include "core/fxcrt/fx_ext.h"
21 #include "core/fxcrt/fx_safe_types.h"
21 #include "core/fxge/fx_freetype.h" 22 #include "core/fxge/fx_freetype.h"
22 #include "third_party/base/numerics/safe_conversions.h" 23 #include "third_party/base/numerics/safe_conversions.h"
23 #include "third_party/base/stl_util.h" 24 #include "third_party/base/stl_util.h"
24 25
25 int TT2PDF(int m, FXFT_Face face) { 26 int TT2PDF(int m, FXFT_Face face) {
26 int upm = FXFT_Get_Face_UnitsPerEM(face); 27 int upm = FXFT_Get_Face_UnitsPerEM(face);
27 if (upm == 0) 28 if (upm == 0)
28 return m; 29 return m;
29 return pdfium::base::checked_cast<int>( 30 return pdfium::base::checked_cast<int>(
30 (static_cast<double>(m) * 1000 + upm / 2) / upm); 31 (static_cast<double>(m) * 1000 + upm / 2) / upm);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 uint32_t srccode = StringToCode(word); 218 uint32_t srccode = StringToCode(word);
218 word = parser.GetWord(); 219 word = parser.GetWord();
219 CFX_WideString destcode = StringToWideString(word); 220 CFX_WideString destcode = StringToWideString(word);
220 int len = destcode.GetLength(); 221 int len = destcode.GetLength();
221 if (len == 0) { 222 if (len == 0) {
222 continue; 223 continue;
223 } 224 }
224 if (len == 1) { 225 if (len == 1) {
225 m_Map[srccode] = destcode.GetAt(0); 226 m_Map[srccode] = destcode.GetAt(0);
226 } else { 227 } else {
227 m_Map[srccode] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; 228 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength();
229 uni *= 0x10000;
230 uni += 0xffff;
231 m_Map[srccode] = uni.ValueOrDie();
228 m_MultiCharBuf.AppendChar(destcode.GetLength()); 232 m_MultiCharBuf.AppendChar(destcode.GetLength());
Tom Sepez 2016/10/04 17:41:21 Drive-by: do we prefer skipping/defaulting the val
npm 2016/10/04 19:24:17 I would say we prefer not crashing whenever possib
dsinclair 2016/10/04 19:27:59 Do we know what a sensible default should be? If t
229 m_MultiCharBuf << destcode; 233 m_MultiCharBuf << destcode;
230 } 234 }
231 } 235 }
232 } else if (word == "beginbfrange") { 236 } else if (word == "beginbfrange") {
233 while (1) { 237 while (1) {
234 CFX_ByteString low, high; 238 CFX_ByteString low, high;
235 low = parser.GetWord(); 239 low = parser.GetWord();
236 if (low.IsEmpty() || low == "endbfrange") { 240 if (low.IsEmpty() || low == "endbfrange") {
237 break; 241 break;
238 } 242 }
239 high = parser.GetWord(); 243 high = parser.GetWord();
240 uint32_t lowcode = StringToCode(low.AsStringC()); 244 uint32_t lowcode = StringToCode(low.AsStringC());
241 uint32_t highcode = 245 uint32_t highcode =
242 (lowcode & 0xffffff00) | (StringToCode(high.AsStringC()) & 0xff); 246 (lowcode & 0xffffff00) | (StringToCode(high.AsStringC()) & 0xff);
243 if (highcode == (uint32_t)-1) { 247 if (highcode == (uint32_t)-1) {
244 break; 248 break;
245 } 249 }
246 CFX_ByteString start(parser.GetWord()); 250 CFX_ByteString start(parser.GetWord());
247 if (start == "[") { 251 if (start == "[") {
248 for (uint32_t code = lowcode; code <= highcode; code++) { 252 for (uint32_t code = lowcode; code <= highcode; code++) {
249 CFX_ByteString dest(parser.GetWord()); 253 CFX_ByteString dest(parser.GetWord());
250 CFX_WideString destcode = StringToWideString(dest.AsStringC()); 254 CFX_WideString destcode = StringToWideString(dest.AsStringC());
251 int len = destcode.GetLength(); 255 int len = destcode.GetLength();
252 if (len == 0) { 256 if (len == 0) {
253 continue; 257 continue;
254 } 258 }
255 if (len == 1) { 259 if (len == 1) {
256 m_Map[code] = destcode.GetAt(0); 260 m_Map[code] = destcode.GetAt(0);
257 } else { 261 } else {
258 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; 262 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength();
263 uni *= 0x10000;
264 uni += 0xffff;
265 m_Map[code] = uni.ValueOrDie();
259 m_MultiCharBuf.AppendChar(destcode.GetLength()); 266 m_MultiCharBuf.AppendChar(destcode.GetLength());
260 m_MultiCharBuf << destcode; 267 m_MultiCharBuf << destcode;
261 } 268 }
262 } 269 }
263 parser.GetWord(); 270 parser.GetWord();
264 } else { 271 } else {
265 CFX_WideString destcode = StringToWideString(start.AsStringC()); 272 CFX_WideString destcode = StringToWideString(start.AsStringC());
266 int len = destcode.GetLength(); 273 int len = destcode.GetLength();
267 uint32_t value = 0; 274 uint32_t value = 0;
268 if (len == 1) { 275 if (len == 1) {
269 value = StringToCode(start.AsStringC()); 276 value = StringToCode(start.AsStringC());
270 for (uint32_t code = lowcode; code <= highcode; code++) { 277 for (uint32_t code = lowcode; code <= highcode; code++) {
271 m_Map[code] = value++; 278 m_Map[code] = value++;
272 } 279 }
273 } else { 280 } else {
274 for (uint32_t code = lowcode; code <= highcode; code++) { 281 for (uint32_t code = lowcode; code <= highcode; code++) {
275 CFX_WideString retcode; 282 CFX_WideString retcode;
276 if (code == lowcode) { 283 if (code == lowcode) {
277 retcode = destcode; 284 retcode = destcode;
278 } else { 285 } else {
279 retcode = StringDataAdd(destcode); 286 retcode = StringDataAdd(destcode);
280 } 287 }
281 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; 288 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength();
dsinclair 2016/10/04 17:15:31 Followup: These 6 lines are basically the same in
npm 2016/10/04 19:24:17 Sounds good
289 uni *= 0x10000;
290 uni += 0xffff;
291 m_Map[code] = uni.ValueOrDie();
282 m_MultiCharBuf.AppendChar(retcode.GetLength()); 292 m_MultiCharBuf.AppendChar(retcode.GetLength());
283 m_MultiCharBuf << retcode; 293 m_MultiCharBuf << retcode;
284 destcode = retcode; 294 destcode = retcode;
285 } 295 }
286 } 296 }
287 } 297 }
288 } 298 }
289 } else if (word == "/Adobe-Korea1-UCS2") { 299 } else if (word == "/Adobe-Korea1-UCS2") {
290 cid_set = CIDSET_KOREA1; 300 cid_set = CIDSET_KOREA1;
291 } else if (word == "/Adobe-Japan1-UCS2") { 301 } else if (word == "/Adobe-Japan1-UCS2") {
292 cid_set = CIDSET_JAPAN1; 302 cid_set = CIDSET_JAPAN1;
293 } else if (word == "/Adobe-CNS1-UCS2") { 303 } else if (word == "/Adobe-CNS1-UCS2") {
294 cid_set = CIDSET_CNS1; 304 cid_set = CIDSET_CNS1;
295 } else if (word == "/Adobe-GB1-UCS2") { 305 } else if (word == "/Adobe-GB1-UCS2") {
296 cid_set = CIDSET_GB1; 306 cid_set = CIDSET_GB1;
297 } 307 }
298 } 308 }
299 if (cid_set) { 309 if (cid_set) {
300 m_pBaseMap = CPDF_ModuleMgr::Get() 310 m_pBaseMap = CPDF_ModuleMgr::Get()
301 ->GetPageModule() 311 ->GetPageModule()
302 ->GetFontGlobals() 312 ->GetFontGlobals()
303 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE); 313 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE);
304 } else { 314 } else {
305 m_pBaseMap = nullptr; 315 m_pBaseMap = nullptr;
306 } 316 }
307 } 317 }
OLDNEW
« 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