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

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

Issue 2392103002: Avoid crashing on CPDF_ToUnicodeMap::Load by using ValueOrDefault() (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 | « core/fpdfapi/font/font_int.h ('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 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/font/font_int.h" 7 #include "core/fpdfapi/font/font_int.h"
8 8
9 #include "core/fpdfapi/cpdf_modulemgr.h" 9 #include "core/fpdfapi/cpdf_modulemgr.h"
10 #include "core/fpdfapi/page/cpdf_form.h" 10 #include "core/fpdfapi/page/cpdf_form.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 return result; 193 return result;
194 } 194 }
195 return result; 195 return result;
196 } 196 }
197 197
198 CPDF_ToUnicodeMap::CPDF_ToUnicodeMap() : m_pBaseMap(nullptr) {} 198 CPDF_ToUnicodeMap::CPDF_ToUnicodeMap() : m_pBaseMap(nullptr) {}
199 199
200 CPDF_ToUnicodeMap::~CPDF_ToUnicodeMap() {} 200 CPDF_ToUnicodeMap::~CPDF_ToUnicodeMap() {}
201 201
202 uint32_t CPDF_ToUnicodeMap::GetUnicode() {
203 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength();
204 uni = uni * 0x10000 + 0xffff;
205 return uni.ValueOrDefault(0);
206 }
207
202 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { 208 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
203 CIDSet cid_set = CIDSET_UNKNOWN; 209 CIDSet cid_set = CIDSET_UNKNOWN;
204 CPDF_StreamAcc stream; 210 CPDF_StreamAcc stream;
205 stream.LoadAllData(pStream, FALSE); 211 stream.LoadAllData(pStream, FALSE);
206 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); 212 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize());
207 while (1) { 213 while (1) {
208 CFX_ByteStringC word = parser.GetWord(); 214 CFX_ByteStringC word = parser.GetWord();
209 if (word.IsEmpty()) { 215 if (word.IsEmpty()) {
210 break; 216 break;
211 } 217 }
212 if (word == "beginbfchar") { 218 if (word == "beginbfchar") {
213 while (1) { 219 while (1) {
214 word = parser.GetWord(); 220 word = parser.GetWord();
215 if (word.IsEmpty() || word == "endbfchar") { 221 if (word.IsEmpty() || word == "endbfchar") {
216 break; 222 break;
217 } 223 }
218 uint32_t srccode = StringToCode(word); 224 uint32_t srccode = StringToCode(word);
219 word = parser.GetWord(); 225 word = parser.GetWord();
220 CFX_WideString destcode = StringToWideString(word); 226 CFX_WideString destcode = StringToWideString(word);
221 int len = destcode.GetLength(); 227 int len = destcode.GetLength();
222 if (len == 0) { 228 if (len == 0) {
223 continue; 229 continue;
224 } 230 }
225 if (len == 1) { 231 if (len == 1) {
226 m_Map[srccode] = destcode.GetAt(0); 232 m_Map[srccode] = destcode.GetAt(0);
227 } else { 233 } else {
228 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength(); 234 m_Map[srccode] = GetUnicode();
229 uni *= 0x10000;
230 uni += 0xffff;
231 m_Map[srccode] = uni.ValueOrDie();
232 m_MultiCharBuf.AppendChar(destcode.GetLength()); 235 m_MultiCharBuf.AppendChar(destcode.GetLength());
233 m_MultiCharBuf << destcode; 236 m_MultiCharBuf << destcode;
234 } 237 }
235 } 238 }
236 } else if (word == "beginbfrange") { 239 } else if (word == "beginbfrange") {
237 while (1) { 240 while (1) {
238 CFX_ByteString low, high; 241 CFX_ByteString low, high;
239 low = parser.GetWord(); 242 low = parser.GetWord();
240 if (low.IsEmpty() || low == "endbfrange") { 243 if (low.IsEmpty() || low == "endbfrange") {
241 break; 244 break;
(...skipping 10 matching lines...) Expand all
252 for (uint32_t code = lowcode; code <= highcode; code++) { 255 for (uint32_t code = lowcode; code <= highcode; code++) {
253 CFX_ByteString dest(parser.GetWord()); 256 CFX_ByteString dest(parser.GetWord());
254 CFX_WideString destcode = StringToWideString(dest.AsStringC()); 257 CFX_WideString destcode = StringToWideString(dest.AsStringC());
255 int len = destcode.GetLength(); 258 int len = destcode.GetLength();
256 if (len == 0) { 259 if (len == 0) {
257 continue; 260 continue;
258 } 261 }
259 if (len == 1) { 262 if (len == 1) {
260 m_Map[code] = destcode.GetAt(0); 263 m_Map[code] = destcode.GetAt(0);
261 } else { 264 } else {
262 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength(); 265 m_Map[code] = GetUnicode();
263 uni *= 0x10000;
264 uni += 0xffff;
265 m_Map[code] = uni.ValueOrDie();
266 m_MultiCharBuf.AppendChar(destcode.GetLength()); 266 m_MultiCharBuf.AppendChar(destcode.GetLength());
267 m_MultiCharBuf << destcode; 267 m_MultiCharBuf << destcode;
268 } 268 }
269 } 269 }
270 parser.GetWord(); 270 parser.GetWord();
271 } else { 271 } else {
272 CFX_WideString destcode = StringToWideString(start.AsStringC()); 272 CFX_WideString destcode = StringToWideString(start.AsStringC());
273 int len = destcode.GetLength(); 273 int len = destcode.GetLength();
274 uint32_t value = 0; 274 uint32_t value = 0;
275 if (len == 1) { 275 if (len == 1) {
276 value = StringToCode(start.AsStringC()); 276 value = StringToCode(start.AsStringC());
277 for (uint32_t code = lowcode; code <= highcode; code++) { 277 for (uint32_t code = lowcode; code <= highcode; code++) {
278 m_Map[code] = value++; 278 m_Map[code] = value++;
279 } 279 }
280 } else { 280 } else {
281 for (uint32_t code = lowcode; code <= highcode; code++) { 281 for (uint32_t code = lowcode; code <= highcode; code++) {
282 CFX_WideString retcode; 282 CFX_WideString retcode;
283 if (code == lowcode) { 283 if (code == lowcode) {
284 retcode = destcode; 284 retcode = destcode;
285 } else { 285 } else {
286 retcode = StringDataAdd(destcode); 286 retcode = StringDataAdd(destcode);
287 } 287 }
288 FX_SAFE_UINT32 uni = m_MultiCharBuf.GetLength(); 288 m_Map[code] = GetUnicode();
289 uni *= 0x10000;
290 uni += 0xffff;
291 m_Map[code] = uni.ValueOrDie();
292 m_MultiCharBuf.AppendChar(retcode.GetLength()); 289 m_MultiCharBuf.AppendChar(retcode.GetLength());
293 m_MultiCharBuf << retcode; 290 m_MultiCharBuf << retcode;
294 destcode = retcode; 291 destcode = retcode;
295 } 292 }
296 } 293 }
297 } 294 }
298 } 295 }
299 } else if (word == "/Adobe-Korea1-UCS2") { 296 } else if (word == "/Adobe-Korea1-UCS2") {
300 cid_set = CIDSET_KOREA1; 297 cid_set = CIDSET_KOREA1;
301 } else if (word == "/Adobe-Japan1-UCS2") { 298 } else if (word == "/Adobe-Japan1-UCS2") {
302 cid_set = CIDSET_JAPAN1; 299 cid_set = CIDSET_JAPAN1;
303 } else if (word == "/Adobe-CNS1-UCS2") { 300 } else if (word == "/Adobe-CNS1-UCS2") {
304 cid_set = CIDSET_CNS1; 301 cid_set = CIDSET_CNS1;
305 } else if (word == "/Adobe-GB1-UCS2") { 302 } else if (word == "/Adobe-GB1-UCS2") {
306 cid_set = CIDSET_GB1; 303 cid_set = CIDSET_GB1;
307 } 304 }
308 } 305 }
309 if (cid_set) { 306 if (cid_set) {
310 m_pBaseMap = CPDF_ModuleMgr::Get() 307 m_pBaseMap = CPDF_ModuleMgr::Get()
311 ->GetPageModule() 308 ->GetPageModule()
312 ->GetFontGlobals() 309 ->GetFontGlobals()
313 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE); 310 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE);
314 } else { 311 } else {
315 m_pBaseMap = nullptr; 312 m_pBaseMap = nullptr;
316 } 313 }
317 } 314 }
OLDNEW
« no previous file with comments | « core/fpdfapi/font/font_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698