Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "parser_int.h" | 7 #include "parser_int.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 FX_BOOL bXRefRebuilt = FALSE; | 216 FX_BOOL bXRefRebuilt = FALSE; |
| 217 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { | 217 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { |
| 218 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); | 218 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); |
| 219 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), | 219 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), |
| 220 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 220 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
| 221 CompareFileSize); | 221 CompareFileSize); |
| 222 if (!pResult) | 222 if (!pResult) |
| 223 m_SortedOffset.Add(startxref_offset); | 223 m_SortedOffset.Add(startxref_offset); |
| 224 | 224 |
| 225 m_Syntax.GetKeyword(); | 225 m_Syntax.GetKeyword(); |
| 226 FX_BOOL bNumber; | 226 bool bNumber; |
| 227 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); | 227 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(&bNumber); |
| 228 if (!bNumber) | 228 if (!bNumber) |
| 229 return PDFPARSE_ERROR_FORMAT; | 229 return PDFPARSE_ERROR_FORMAT; |
| 230 | 230 |
| 231 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 231 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
| 232 if (!LoadAllCrossRefV4(m_LastXRefOffset) && | 232 if (!LoadAllCrossRefV4(m_LastXRefOffset) && |
| 233 !LoadAllCrossRefV5(m_LastXRefOffset)) { | 233 !LoadAllCrossRefV5(m_LastXRefOffset)) { |
| 234 if (!RebuildCrossRef()) | 234 if (!RebuildCrossRef()) |
| 235 return PDFPARSE_ERROR_FORMAT; | 235 return PDFPARSE_ERROR_FORMAT; |
| 236 | 236 |
| 237 bXRefRebuilt = TRUE; | 237 bXRefRebuilt = TRUE; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 return false; | 517 return false; |
| 518 | 518 |
| 519 if (!FindPosInOffsets(pos)) | 519 if (!FindPosInOffsets(pos)) |
| 520 m_SortedOffset.Add(pos); | 520 m_SortedOffset.Add(pos); |
| 521 | 521 |
| 522 if (streampos && !FindPosInOffsets(streampos)) | 522 if (streampos && !FindPosInOffsets(streampos)) |
| 523 m_SortedOffset.Add(streampos); | 523 m_SortedOffset.Add(streampos); |
| 524 | 524 |
| 525 while (1) { | 525 while (1) { |
| 526 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 526 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 527 FX_BOOL bIsNumber; | 527 bool bIsNumber; |
| 528 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 528 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 529 if (word.IsEmpty()) | 529 if (word.IsEmpty()) |
| 530 return false; | 530 return false; |
| 531 | 531 |
| 532 if (!bIsNumber) { | 532 if (!bIsNumber) { |
| 533 m_Syntax.RestorePos(SavedPos); | 533 m_Syntax.RestorePos(SavedPos); |
| 534 break; | 534 break; |
| 535 } | 535 } |
| 536 FX_DWORD start_objnum = FXSYS_atoi(word); | 536 FX_DWORD start_objnum = FXSYS_atoi(word); |
| 537 if (start_objnum >= kMaxObjectNumber) | 537 if (start_objnum >= kMaxObjectNumber) |
| 538 return false; | 538 return false; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 } else { | 871 } else { |
| 872 if (pObj->IsStream()) { | 872 if (pObj->IsStream()) { |
| 873 m_pTrailer = ToDictionary(pTrailer->Clone()); | 873 m_pTrailer = ToDictionary(pTrailer->Clone()); |
| 874 pObj->Release(); | 874 pObj->Release(); |
| 875 } else { | 875 } else { |
| 876 m_pTrailer = pTrailer; | 876 m_pTrailer = pTrailer; |
| 877 } | 877 } |
| 878 FX_FILESIZE dwSavePos = m_Syntax.SavePos(); | 878 FX_FILESIZE dwSavePos = m_Syntax.SavePos(); |
| 879 CFX_ByteString strWord = m_Syntax.GetKeyword(); | 879 CFX_ByteString strWord = m_Syntax.GetKeyword(); |
| 880 if (!strWord.Compare("startxref")) { | 880 if (!strWord.Compare("startxref")) { |
| 881 FX_BOOL bNumber = FALSE; | 881 bool bNumber; |
| 882 CFX_ByteString bsOffset = m_Syntax.GetNextWord(bNumber); | 882 CFX_ByteString bsOffset = |
| 883 m_Syntax.GetNextWord(&bNumber); | |
| 883 if (bNumber) { | 884 if (bNumber) { |
| 884 m_LastXRefOffset = FXSYS_atoi(bsOffset); | 885 m_LastXRefOffset = FXSYS_atoi(bsOffset); |
| 885 } | 886 } |
| 886 } | 887 } |
| 887 m_Syntax.RestorePos(dwSavePos); | 888 m_Syntax.RestorePos(dwSavePos); |
| 888 } | 889 } |
| 889 } else { | 890 } else { |
| 890 pObj->Release(); | 891 pObj->Release(); |
| 891 } | 892 } |
| 892 } | 893 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1302 | 1303 |
| 1303 if (m_V5Type[objnum] != 1) | 1304 if (m_V5Type[objnum] != 1) |
| 1304 return; | 1305 return; |
| 1305 | 1306 |
| 1306 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1307 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| 1307 if (pos == 0) { | 1308 if (pos == 0) { |
| 1308 return; | 1309 return; |
| 1309 } | 1310 } |
| 1310 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1311 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1311 m_Syntax.RestorePos(pos); | 1312 m_Syntax.RestorePos(pos); |
| 1312 FX_BOOL bIsNumber; | 1313 bool bIsNumber; |
| 1313 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1314 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 1314 if (!bIsNumber) { | 1315 if (!bIsNumber) { |
| 1315 m_Syntax.RestorePos(SavedPos); | 1316 m_Syntax.RestorePos(SavedPos); |
| 1316 return; | 1317 return; |
| 1317 } | 1318 } |
| 1318 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1319 FX_DWORD parser_objnum = FXSYS_atoi(word); |
| 1319 if (parser_objnum && parser_objnum != objnum) { | 1320 if (parser_objnum && parser_objnum != objnum) { |
| 1320 m_Syntax.RestorePos(SavedPos); | 1321 m_Syntax.RestorePos(SavedPos); |
| 1321 return; | 1322 return; |
| 1322 } | 1323 } |
| 1323 word = m_Syntax.GetNextWord(bIsNumber); | 1324 word = m_Syntax.GetNextWord(&bIsNumber); |
| 1324 if (!bIsNumber) { | 1325 if (!bIsNumber) { |
| 1325 m_Syntax.RestorePos(SavedPos); | 1326 m_Syntax.RestorePos(SavedPos); |
| 1326 return; | 1327 return; |
| 1327 } | 1328 } |
| 1328 if (m_Syntax.GetKeyword() != "obj") { | 1329 if (m_Syntax.GetKeyword() != "obj") { |
| 1329 m_Syntax.RestorePos(SavedPos); | 1330 m_Syntax.RestorePos(SavedPos); |
| 1330 return; | 1331 return; |
| 1331 } | 1332 } |
| 1332 void* pResult = | 1333 void* pResult = |
| 1333 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1334 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 1334 sizeof(FX_FILESIZE), CompareFileSize); | 1335 sizeof(FX_FILESIZE), CompareFileSize); |
| 1335 if (!pResult) { | 1336 if (!pResult) { |
| 1336 m_Syntax.RestorePos(SavedPos); | 1337 m_Syntax.RestorePos(SavedPos); |
| 1337 return; | 1338 return; |
| 1338 } | 1339 } |
| 1339 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; | 1340 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; |
| 1340 FX_BOOL bNextOffValid = FALSE; | 1341 FX_BOOL bNextOffValid = FALSE; |
| 1341 if (nextoff != pos) { | 1342 if (nextoff != pos) { |
| 1342 m_Syntax.RestorePos(nextoff); | 1343 m_Syntax.RestorePos(nextoff); |
| 1343 word = m_Syntax.GetNextWord(bIsNumber); | 1344 word = m_Syntax.GetNextWord(&bIsNumber); |
| 1344 if (word == "xref") { | 1345 if (word == "xref") { |
| 1345 bNextOffValid = TRUE; | 1346 bNextOffValid = TRUE; |
| 1346 } else if (bIsNumber) { | 1347 } else if (bIsNumber) { |
| 1347 word = m_Syntax.GetNextWord(bIsNumber); | 1348 word = m_Syntax.GetNextWord(&bIsNumber); |
| 1348 if (bIsNumber && m_Syntax.GetKeyword() == "obj") { | 1349 if (bIsNumber && m_Syntax.GetKeyword() == "obj") { |
| 1349 bNextOffValid = TRUE; | 1350 bNextOffValid = TRUE; |
| 1350 } | 1351 } |
| 1351 } | 1352 } |
| 1352 } | 1353 } |
| 1353 if (!bNextOffValid) { | 1354 if (!bNextOffValid) { |
| 1354 m_Syntax.RestorePos(pos); | 1355 m_Syntax.RestorePos(pos); |
| 1355 while (1) { | 1356 while (1) { |
| 1356 if (m_Syntax.GetKeyword() == "endobj") { | 1357 if (m_Syntax.GetKeyword() == "endobj") { |
| 1357 break; | 1358 break; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1368 m_Syntax.ReadBlock(pBuffer, size); | 1369 m_Syntax.ReadBlock(pBuffer, size); |
| 1369 m_Syntax.RestorePos(SavedPos); | 1370 m_Syntax.RestorePos(SavedPos); |
| 1370 } | 1371 } |
| 1371 | 1372 |
| 1372 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, | 1373 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, |
| 1373 FX_FILESIZE pos, | 1374 FX_FILESIZE pos, |
| 1374 FX_DWORD objnum, | 1375 FX_DWORD objnum, |
| 1375 PARSE_CONTEXT* pContext) { | 1376 PARSE_CONTEXT* pContext) { |
| 1376 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1377 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1377 m_Syntax.RestorePos(pos); | 1378 m_Syntax.RestorePos(pos); |
| 1378 FX_BOOL bIsNumber; | 1379 bool bIsNumber; |
| 1379 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1380 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 1380 if (!bIsNumber) { | 1381 if (!bIsNumber) { |
| 1381 m_Syntax.RestorePos(SavedPos); | 1382 m_Syntax.RestorePos(SavedPos); |
| 1382 return NULL; | 1383 return NULL; |
| 1383 } | 1384 } |
| 1384 FX_FILESIZE objOffset = m_Syntax.SavePos(); | 1385 FX_FILESIZE objOffset = m_Syntax.SavePos(); |
| 1385 objOffset -= word.GetLength(); | 1386 objOffset -= word.GetLength(); |
| 1386 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1387 FX_DWORD parser_objnum = FXSYS_atoi(word); |
| 1387 if (objnum && parser_objnum != objnum) { | 1388 if (objnum && parser_objnum != objnum) { |
| 1388 m_Syntax.RestorePos(SavedPos); | 1389 m_Syntax.RestorePos(SavedPos); |
| 1389 return NULL; | 1390 return NULL; |
| 1390 } | 1391 } |
| 1391 word = m_Syntax.GetNextWord(bIsNumber); | 1392 word = m_Syntax.GetNextWord(&bIsNumber); |
| 1392 if (!bIsNumber) { | 1393 if (!bIsNumber) { |
| 1393 m_Syntax.RestorePos(SavedPos); | 1394 m_Syntax.RestorePos(SavedPos); |
| 1394 return NULL; | 1395 return NULL; |
| 1395 } | 1396 } |
| 1396 FX_DWORD parser_gennum = FXSYS_atoi(word); | 1397 FX_DWORD parser_gennum = FXSYS_atoi(word); |
| 1397 if (m_Syntax.GetKeyword() != "obj") { | 1398 if (m_Syntax.GetKeyword() != "obj") { |
| 1398 m_Syntax.RestorePos(SavedPos); | 1399 m_Syntax.RestorePos(SavedPos); |
| 1399 return NULL; | 1400 return NULL; |
| 1400 } | 1401 } |
| 1401 CPDF_Object* pObj = | 1402 CPDF_Object* pObj = |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1415 return pObj; | 1416 return pObj; |
| 1416 } | 1417 } |
| 1417 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 1418 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( |
| 1418 CPDF_IndirectObjects* pObjList, | 1419 CPDF_IndirectObjects* pObjList, |
| 1419 FX_FILESIZE pos, | 1420 FX_FILESIZE pos, |
| 1420 FX_DWORD objnum, | 1421 FX_DWORD objnum, |
| 1421 struct PARSE_CONTEXT* pContext, | 1422 struct PARSE_CONTEXT* pContext, |
| 1422 FX_FILESIZE* pResultPos) { | 1423 FX_FILESIZE* pResultPos) { |
| 1423 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1424 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1424 m_Syntax.RestorePos(pos); | 1425 m_Syntax.RestorePos(pos); |
| 1425 FX_BOOL bIsNumber; | 1426 bool bIsNumber; |
| 1426 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1427 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 1427 if (!bIsNumber) { | 1428 if (!bIsNumber) { |
| 1428 m_Syntax.RestorePos(SavedPos); | 1429 m_Syntax.RestorePos(SavedPos); |
| 1429 return NULL; | 1430 return NULL; |
| 1430 } | 1431 } |
| 1431 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1432 FX_DWORD parser_objnum = FXSYS_atoi(word); |
| 1432 if (objnum && parser_objnum != objnum) { | 1433 if (objnum && parser_objnum != objnum) { |
| 1433 m_Syntax.RestorePos(SavedPos); | 1434 m_Syntax.RestorePos(SavedPos); |
| 1434 return NULL; | 1435 return NULL; |
| 1435 } | 1436 } |
| 1436 word = m_Syntax.GetNextWord(bIsNumber); | 1437 word = m_Syntax.GetNextWord(&bIsNumber); |
| 1437 if (!bIsNumber) { | 1438 if (!bIsNumber) { |
| 1438 m_Syntax.RestorePos(SavedPos); | 1439 m_Syntax.RestorePos(SavedPos); |
| 1439 return NULL; | 1440 return NULL; |
| 1440 } | 1441 } |
| 1441 FX_DWORD gennum = FXSYS_atoi(word); | 1442 FX_DWORD gennum = FXSYS_atoi(word); |
| 1442 if (m_Syntax.GetKeyword() != "obj") { | 1443 if (m_Syntax.GetKeyword() != "obj") { |
| 1443 m_Syntax.RestorePos(SavedPos); | 1444 m_Syntax.RestorePos(SavedPos); |
| 1444 return NULL; | 1445 return NULL; |
| 1445 } | 1446 } |
| 1446 CPDF_Object* pObj = | 1447 CPDF_Object* pObj = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1488 return; | 1489 return; |
| 1489 } | 1490 } |
| 1490 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); | 1491 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); |
| 1491 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 1492 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); |
| 1492 } | 1493 } |
| 1493 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, | 1494 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, |
| 1494 FX_DWORD offset) { | 1495 FX_DWORD offset) { |
| 1495 m_Syntax.InitParser(pFileAccess, offset); | 1496 m_Syntax.InitParser(pFileAccess, offset); |
| 1496 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); | 1497 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); |
| 1497 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1498 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1498 FX_BOOL bIsNumber; | 1499 bool bIsNumber; |
| 1499 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1500 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 1500 if (!bIsNumber) { | 1501 if (!bIsNumber) { |
| 1501 return FALSE; | 1502 return FALSE; |
| 1502 } | 1503 } |
| 1503 FX_DWORD objnum = FXSYS_atoi(word); | 1504 FX_DWORD objnum = FXSYS_atoi(word); |
| 1504 word = m_Syntax.GetNextWord(bIsNumber); | 1505 word = m_Syntax.GetNextWord(&bIsNumber); |
| 1505 if (!bIsNumber) { | 1506 if (!bIsNumber) { |
| 1506 return FALSE; | 1507 return FALSE; |
| 1507 } | 1508 } |
| 1508 FX_DWORD gennum = FXSYS_atoi(word); | 1509 FX_DWORD gennum = FXSYS_atoi(word); |
| 1509 if (m_Syntax.GetKeyword() != "obj") { | 1510 if (m_Syntax.GetKeyword() != "obj") { |
| 1510 m_Syntax.RestorePos(SavedPos); | 1511 m_Syntax.RestorePos(SavedPos); |
| 1511 return FALSE; | 1512 return FALSE; |
| 1512 } | 1513 } |
| 1513 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); | 1514 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); |
| 1514 if (!m_pLinearized) { | 1515 if (!m_pLinearized) { |
| 1515 return FALSE; | 1516 return FALSE; |
| 1516 } | 1517 } |
| 1517 | 1518 |
| 1518 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1519 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1519 if (pDict && pDict->GetElement("Linearized")) { | 1520 if (pDict && pDict->GetElement("Linearized")) { |
| 1520 m_Syntax.GetNextWord(bIsNumber); | 1521 m_Syntax.GetNextWord(nullptr); |
| 1521 | 1522 |
| 1522 CPDF_Object* pLen = pDict->GetElement("L"); | 1523 CPDF_Object* pLen = pDict->GetElement("L"); |
| 1523 if (!pLen) { | 1524 if (!pLen) { |
| 1524 m_pLinearized->Release(); | 1525 m_pLinearized->Release(); |
| 1525 m_pLinearized = NULL; | 1526 m_pLinearized = NULL; |
| 1526 return FALSE; | 1527 return FALSE; |
| 1527 } | 1528 } |
| 1528 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { | 1529 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { |
| 1529 return FALSE; | 1530 return FALSE; |
| 1530 } | 1531 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1763 return TRUE; | 1764 return TRUE; |
| 1764 } | 1765 } |
| 1765 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) { | 1766 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) { |
| 1766 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { | 1767 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { |
| 1767 return FALSE; | 1768 return FALSE; |
| 1768 } | 1769 } |
| 1769 m_Pos += size; | 1770 m_Pos += size; |
| 1770 return TRUE; | 1771 return TRUE; |
| 1771 } | 1772 } |
| 1772 #define MAX_WORD_BUFFER 256 | 1773 #define MAX_WORD_BUFFER 256 |
| 1773 void CPDF_SyntaxParser::GetNextWord() { | 1774 bool CPDF_SyntaxParser::GetNextWordInternal() { |
|
Wei Li
2016/01/05 03:34:17
Consider using the similar prototype as GetNextWor
Lei Zhang
2016/01/06 01:19:22
Sure.
| |
| 1774 m_WordSize = 0; | 1775 m_WordSize = 0; |
| 1775 m_bIsNumber = TRUE; | 1776 bool bIsNumber = true; |
| 1776 uint8_t ch; | 1777 uint8_t ch; |
| 1777 if (!GetNextChar(ch)) { | 1778 if (!GetNextChar(ch)) { |
| 1778 return; | 1779 return bIsNumber; |
| 1779 } | 1780 } |
| 1780 while (1) { | 1781 while (1) { |
| 1781 while (PDFCharIsWhitespace(ch)) { | 1782 while (PDFCharIsWhitespace(ch)) { |
| 1782 if (!GetNextChar(ch)) | 1783 if (!GetNextChar(ch)) |
| 1783 return; | 1784 return bIsNumber; |
| 1784 } | 1785 } |
| 1785 if (ch != '%') | 1786 if (ch != '%') |
| 1786 break; | 1787 break; |
| 1787 | 1788 |
| 1788 while (1) { | 1789 while (1) { |
| 1789 if (!GetNextChar(ch)) | 1790 if (!GetNextChar(ch)) |
| 1790 return; | 1791 return bIsNumber; |
| 1791 if (PDFCharIsLineEnding(ch)) | 1792 if (PDFCharIsLineEnding(ch)) |
| 1792 break; | 1793 break; |
| 1793 } | 1794 } |
| 1794 } | 1795 } |
| 1795 | 1796 |
| 1796 if (PDFCharIsDelimiter(ch)) { | 1797 if (PDFCharIsDelimiter(ch)) { |
| 1797 m_bIsNumber = FALSE; | 1798 bIsNumber = false; |
| 1798 m_WordBuffer[m_WordSize++] = ch; | 1799 m_WordBuffer[m_WordSize++] = ch; |
| 1799 if (ch == '/') { | 1800 if (ch == '/') { |
| 1800 while (1) { | 1801 while (1) { |
| 1801 if (!GetNextChar(ch)) | 1802 if (!GetNextChar(ch)) |
| 1802 return; | 1803 return bIsNumber; |
| 1803 | 1804 |
| 1804 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { | 1805 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { |
| 1805 m_Pos--; | 1806 m_Pos--; |
| 1806 return; | 1807 return bIsNumber; |
| 1807 } | 1808 } |
| 1808 | 1809 |
| 1809 if (m_WordSize < MAX_WORD_BUFFER) | 1810 if (m_WordSize < MAX_WORD_BUFFER) |
| 1810 m_WordBuffer[m_WordSize++] = ch; | 1811 m_WordBuffer[m_WordSize++] = ch; |
| 1811 } | 1812 } |
| 1812 } else if (ch == '<') { | 1813 } else if (ch == '<') { |
| 1813 if (!GetNextChar(ch)) | 1814 if (!GetNextChar(ch)) |
| 1814 return; | 1815 return bIsNumber; |
| 1815 if (ch == '<') | 1816 if (ch == '<') |
| 1816 m_WordBuffer[m_WordSize++] = ch; | 1817 m_WordBuffer[m_WordSize++] = ch; |
| 1817 else | 1818 else |
| 1818 m_Pos--; | 1819 m_Pos--; |
| 1819 } else if (ch == '>') { | 1820 } else if (ch == '>') { |
| 1820 if (!GetNextChar(ch)) | 1821 if (!GetNextChar(ch)) |
| 1821 return; | 1822 return bIsNumber; |
| 1822 if (ch == '>') | 1823 if (ch == '>') |
| 1823 m_WordBuffer[m_WordSize++] = ch; | 1824 m_WordBuffer[m_WordSize++] = ch; |
| 1824 else | 1825 else |
| 1825 m_Pos--; | 1826 m_Pos--; |
| 1826 } | 1827 } |
| 1827 return; | 1828 return bIsNumber; |
| 1828 } | 1829 } |
| 1829 | 1830 |
| 1830 while (1) { | 1831 while (1) { |
| 1831 if (m_WordSize < MAX_WORD_BUFFER) | 1832 if (m_WordSize < MAX_WORD_BUFFER) |
| 1832 m_WordBuffer[m_WordSize++] = ch; | 1833 m_WordBuffer[m_WordSize++] = ch; |
| 1833 | 1834 |
| 1834 if (!PDFCharIsNumeric(ch)) | 1835 if (!PDFCharIsNumeric(ch)) |
| 1835 m_bIsNumber = FALSE; | 1836 bIsNumber = false; |
| 1836 if (!GetNextChar(ch)) | 1837 if (!GetNextChar(ch)) |
| 1837 return; | 1838 return bIsNumber; |
| 1838 | 1839 |
| 1839 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { | 1840 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { |
| 1840 m_Pos--; | 1841 m_Pos--; |
| 1841 break; | 1842 break; |
| 1842 } | 1843 } |
| 1843 } | 1844 } |
| 1845 return bIsNumber; | |
| 1844 } | 1846 } |
| 1847 | |
| 1845 CFX_ByteString CPDF_SyntaxParser::ReadString() { | 1848 CFX_ByteString CPDF_SyntaxParser::ReadString() { |
| 1846 uint8_t ch; | 1849 uint8_t ch; |
| 1847 if (!GetNextChar(ch)) { | 1850 if (!GetNextChar(ch)) { |
| 1848 return CFX_ByteString(); | 1851 return CFX_ByteString(); |
| 1849 } | 1852 } |
| 1850 CFX_ByteTextBuf buf; | 1853 CFX_ByteTextBuf buf; |
| 1851 int32_t parlevel = 0; | 1854 int32_t parlevel = 0; |
| 1852 int32_t status = 0, iEscCode = 0; | 1855 int32_t status = 0, iEscCode = 0; |
| 1853 while (1) { | 1856 while (1) { |
| 1854 switch (status) { | 1857 switch (status) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1992 while (1) { | 1995 while (1) { |
| 1993 if (!GetNextChar(ch)) | 1996 if (!GetNextChar(ch)) |
| 1994 return; | 1997 return; |
| 1995 if (PDFCharIsLineEnding(ch)) | 1998 if (PDFCharIsLineEnding(ch)) |
| 1996 break; | 1999 break; |
| 1997 } | 2000 } |
| 1998 } | 2001 } |
| 1999 m_Pos--; | 2002 m_Pos--; |
| 2000 } | 2003 } |
| 2001 | 2004 |
| 2002 CFX_ByteString CPDF_SyntaxParser::GetNextWord(FX_BOOL& bIsNumber) { | 2005 CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool* bIsNumber) { |
| 2003 GetNextWord(); | 2006 bool bWordIsNumber = GetNextWordInternal(); |
| 2004 bIsNumber = m_bIsNumber; | 2007 if (bIsNumber) |
| 2008 *bIsNumber = bWordIsNumber; | |
| 2005 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2009 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
| 2006 } | 2010 } |
| 2011 | |
| 2007 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { | 2012 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { |
| 2008 GetNextWord(); | 2013 return GetNextWord(nullptr); |
| 2009 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | |
| 2010 } | 2014 } |
| 2015 | |
| 2011 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, | 2016 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, |
| 2012 FX_DWORD objnum, | 2017 FX_DWORD objnum, |
| 2013 FX_DWORD gennum, | 2018 FX_DWORD gennum, |
| 2014 PARSE_CONTEXT* pContext, | 2019 PARSE_CONTEXT* pContext, |
| 2015 FX_BOOL bDecrypt) { | 2020 FX_BOOL bDecrypt) { |
| 2016 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2021 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
| 2017 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2022 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
| 2018 return NULL; | 2023 return NULL; |
| 2019 } | 2024 } |
| 2020 FX_FILESIZE SavedPos = m_Pos; | 2025 FX_FILESIZE SavedPos = m_Pos; |
| 2021 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2026 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
| 2022 FX_BOOL bIsNumber; | 2027 bool bIsNumber; |
| 2023 CFX_ByteString word = GetNextWord(bIsNumber); | 2028 CFX_ByteString word = GetNextWord(&bIsNumber); |
| 2024 if (word.GetLength() == 0) { | 2029 if (word.GetLength() == 0) { |
| 2025 if (bTypeOnly) | 2030 if (bTypeOnly) |
| 2026 return (CPDF_Object*)PDFOBJ_INVALID; | 2031 return (CPDF_Object*)PDFOBJ_INVALID; |
| 2027 return NULL; | 2032 return NULL; |
| 2028 } | 2033 } |
| 2029 if (bIsNumber) { | 2034 if (bIsNumber) { |
| 2030 FX_FILESIZE SavedPos = m_Pos; | 2035 FX_FILESIZE SavedPos = m_Pos; |
| 2031 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2036 CFX_ByteString nextword = GetNextWord(&bIsNumber); |
| 2032 if (bIsNumber) { | 2037 if (bIsNumber) { |
| 2033 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 2038 CFX_ByteString nextword2 = GetNextWord(nullptr); |
| 2034 if (nextword2 == "R") { | 2039 if (nextword2 == "R") { |
| 2035 FX_DWORD objnum = FXSYS_atoi(word); | 2040 FX_DWORD objnum = FXSYS_atoi(word); |
| 2036 if (bTypeOnly) | 2041 if (bTypeOnly) |
| 2037 return (CPDF_Object*)PDFOBJ_REFERENCE; | 2042 return (CPDF_Object*)PDFOBJ_REFERENCE; |
| 2038 return new CPDF_Reference(pObjList, objnum); | 2043 return new CPDF_Reference(pObjList, objnum); |
| 2039 } | 2044 } |
| 2040 } | 2045 } |
| 2041 m_Pos = SavedPos; | 2046 m_Pos = SavedPos; |
| 2042 if (bTypeOnly) | 2047 if (bTypeOnly) |
| 2043 return (CPDF_Object*)PDFOBJ_NUMBER; | 2048 return (CPDF_Object*)PDFOBJ_NUMBER; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2091 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2096 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
| 2092 | 2097 |
| 2093 if (pContext) | 2098 if (pContext) |
| 2094 pContext->m_DictStart = SavedPos; | 2099 pContext->m_DictStart = SavedPos; |
| 2095 | 2100 |
| 2096 int32_t nKeys = 0; | 2101 int32_t nKeys = 0; |
| 2097 FX_FILESIZE dwSignValuePos = 0; | 2102 FX_FILESIZE dwSignValuePos = 0; |
| 2098 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 2103 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
| 2099 new CPDF_Dictionary); | 2104 new CPDF_Dictionary); |
| 2100 while (1) { | 2105 while (1) { |
| 2101 FX_BOOL bIsNumber; | 2106 CFX_ByteString key = GetNextWord(nullptr); |
| 2102 CFX_ByteString key = GetNextWord(bIsNumber); | |
| 2103 if (key.IsEmpty()) | 2107 if (key.IsEmpty()) |
| 2104 return nullptr; | 2108 return nullptr; |
| 2105 | 2109 |
| 2106 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 2110 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
| 2107 if (key == ">>") | 2111 if (key == ">>") |
| 2108 break; | 2112 break; |
| 2109 | 2113 |
| 2110 if (key == "endobj") { | 2114 if (key == "endobj") { |
| 2111 m_Pos = SavedPos; | 2115 m_Pos = SavedPos; |
| 2112 break; | 2116 break; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2143 pDict->SetAt("Contents", pObj); | 2147 pDict->SetAt("Contents", pObj); |
| 2144 m_Pos = dwSavePos; | 2148 m_Pos = dwSavePos; |
| 2145 } | 2149 } |
| 2146 if (pContext) { | 2150 if (pContext) { |
| 2147 pContext->m_DictEnd = m_Pos; | 2151 pContext->m_DictEnd = m_Pos; |
| 2148 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2152 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
| 2149 return pDict.release(); | 2153 return pDict.release(); |
| 2150 } | 2154 } |
| 2151 } | 2155 } |
| 2152 FX_FILESIZE SavedPos = m_Pos; | 2156 FX_FILESIZE SavedPos = m_Pos; |
| 2153 FX_BOOL bIsNumber; | 2157 CFX_ByteString nextword = GetNextWord(nullptr); |
| 2154 CFX_ByteString nextword = GetNextWord(bIsNumber); | |
| 2155 if (nextword != "stream") { | 2158 if (nextword != "stream") { |
| 2156 m_Pos = SavedPos; | 2159 m_Pos = SavedPos; |
| 2157 return pDict.release(); | 2160 return pDict.release(); |
| 2158 } | 2161 } |
| 2159 | 2162 |
| 2160 return ReadStream(pDict.release(), pContext, objnum, gennum); | 2163 return ReadStream(pDict.release(), pContext, objnum, gennum); |
| 2161 } | 2164 } |
| 2162 if (word == ">>") { | 2165 if (word == ">>") { |
| 2163 m_Pos = SavedPos; | 2166 m_Pos = SavedPos; |
| 2164 return nullptr; | 2167 return nullptr; |
| 2165 } | 2168 } |
| 2166 if (bTypeOnly) | 2169 if (bTypeOnly) |
| 2167 return (CPDF_Object*)PDFOBJ_INVALID; | 2170 return (CPDF_Object*)PDFOBJ_INVALID; |
| 2168 | 2171 |
| 2169 return nullptr; | 2172 return nullptr; |
| 2170 } | 2173 } |
| 2171 | 2174 |
| 2172 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( | 2175 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( |
| 2173 CPDF_IndirectObjects* pObjList, | 2176 CPDF_IndirectObjects* pObjList, |
| 2174 FX_DWORD objnum, | 2177 FX_DWORD objnum, |
| 2175 FX_DWORD gennum, | 2178 FX_DWORD gennum, |
| 2176 struct PARSE_CONTEXT* pContext) { | 2179 struct PARSE_CONTEXT* pContext) { |
| 2177 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2180 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
| 2178 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2181 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
| 2179 return NULL; | 2182 return NULL; |
| 2180 } | 2183 } |
| 2181 FX_FILESIZE SavedPos = m_Pos; | 2184 FX_FILESIZE SavedPos = m_Pos; |
| 2182 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2185 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
| 2183 FX_BOOL bIsNumber; | 2186 bool bIsNumber; |
| 2184 CFX_ByteString word = GetNextWord(bIsNumber); | 2187 CFX_ByteString word = GetNextWord(&bIsNumber); |
| 2185 if (word.GetLength() == 0) { | 2188 if (word.GetLength() == 0) { |
| 2186 if (bTypeOnly) | 2189 if (bTypeOnly) |
| 2187 return (CPDF_Object*)PDFOBJ_INVALID; | 2190 return (CPDF_Object*)PDFOBJ_INVALID; |
| 2188 return nullptr; | 2191 return nullptr; |
| 2189 } | 2192 } |
| 2190 if (bIsNumber) { | 2193 if (bIsNumber) { |
| 2191 FX_FILESIZE SavedPos = m_Pos; | 2194 FX_FILESIZE SavedPos = m_Pos; |
| 2192 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2195 CFX_ByteString nextword = GetNextWord(&bIsNumber); |
| 2193 if (bIsNumber) { | 2196 if (bIsNumber) { |
| 2194 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 2197 CFX_ByteString nextword2 = GetNextWord(nullptr); |
| 2195 if (nextword2 == "R") { | 2198 if (nextword2 == "R") { |
| 2196 if (bTypeOnly) | 2199 if (bTypeOnly) |
| 2197 return (CPDF_Object*)PDFOBJ_REFERENCE; | 2200 return (CPDF_Object*)PDFOBJ_REFERENCE; |
| 2198 FX_DWORD objnum = FXSYS_atoi(word); | 2201 FX_DWORD objnum = FXSYS_atoi(word); |
| 2199 return new CPDF_Reference(pObjList, objnum); | 2202 return new CPDF_Reference(pObjList, objnum); |
| 2200 } | 2203 } |
| 2201 } | 2204 } |
| 2202 m_Pos = SavedPos; | 2205 m_Pos = SavedPos; |
| 2203 if (bTypeOnly) | 2206 if (bTypeOnly) |
| 2204 return (CPDF_Object*)PDFOBJ_NUMBER; | 2207 return (CPDF_Object*)PDFOBJ_NUMBER; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2247 } | 2250 } |
| 2248 if (word == "<<") { | 2251 if (word == "<<") { |
| 2249 if (bTypeOnly) | 2252 if (bTypeOnly) |
| 2250 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2253 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
| 2251 if (pContext) | 2254 if (pContext) |
| 2252 pContext->m_DictStart = SavedPos; | 2255 pContext->m_DictStart = SavedPos; |
| 2253 | 2256 |
| 2254 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 2257 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
| 2255 new CPDF_Dictionary); | 2258 new CPDF_Dictionary); |
| 2256 while (1) { | 2259 while (1) { |
| 2257 FX_BOOL bIsNumber; | |
| 2258 FX_FILESIZE SavedPos = m_Pos; | 2260 FX_FILESIZE SavedPos = m_Pos; |
| 2259 CFX_ByteString key = GetNextWord(bIsNumber); | 2261 CFX_ByteString key = GetNextWord(nullptr); |
| 2260 if (key.IsEmpty()) | 2262 if (key.IsEmpty()) |
| 2261 return nullptr; | 2263 return nullptr; |
| 2262 | 2264 |
| 2263 if (key == ">>") | 2265 if (key == ">>") |
| 2264 break; | 2266 break; |
| 2265 | 2267 |
| 2266 if (key == "endobj") { | 2268 if (key == "endobj") { |
| 2267 m_Pos = SavedPos; | 2269 m_Pos = SavedPos; |
| 2268 break; | 2270 break; |
| 2269 } | 2271 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2284 obj.release()); | 2286 obj.release()); |
| 2285 } | 2287 } |
| 2286 } | 2288 } |
| 2287 if (pContext) { | 2289 if (pContext) { |
| 2288 pContext->m_DictEnd = m_Pos; | 2290 pContext->m_DictEnd = m_Pos; |
| 2289 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2291 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
| 2290 return pDict.release(); | 2292 return pDict.release(); |
| 2291 } | 2293 } |
| 2292 } | 2294 } |
| 2293 FX_FILESIZE SavedPos = m_Pos; | 2295 FX_FILESIZE SavedPos = m_Pos; |
| 2294 FX_BOOL bIsNumber; | 2296 CFX_ByteString nextword = GetNextWord(nullptr); |
| 2295 CFX_ByteString nextword = GetNextWord(bIsNumber); | |
| 2296 if (nextword != "stream") { | 2297 if (nextword != "stream") { |
| 2297 m_Pos = SavedPos; | 2298 m_Pos = SavedPos; |
| 2298 return pDict.release(); | 2299 return pDict.release(); |
| 2299 } | 2300 } |
| 2300 | 2301 |
| 2301 return ReadStream(pDict.release(), pContext, objnum, gennum); | 2302 return ReadStream(pDict.release(), pContext, objnum, gennum); |
| 2302 } | 2303 } |
| 2303 if (word == ">>") { | 2304 if (word == ">>") { |
| 2304 m_Pos = SavedPos; | 2305 m_Pos = SavedPos; |
| 2305 return nullptr; | 2306 return nullptr; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2349 if (!pCryptoHandler) { | 2350 if (!pCryptoHandler) { |
| 2350 FX_BOOL bSearchForKeyword = TRUE; | 2351 FX_BOOL bSearchForKeyword = TRUE; |
| 2351 if (len >= 0) { | 2352 if (len >= 0) { |
| 2352 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; | 2353 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; |
| 2353 pos += len; | 2354 pos += len; |
| 2354 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { | 2355 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { |
| 2355 m_Pos = pos.ValueOrDie(); | 2356 m_Pos = pos.ValueOrDie(); |
| 2356 } | 2357 } |
| 2357 m_Pos += ReadEOLMarkers(m_Pos); | 2358 m_Pos += ReadEOLMarkers(m_Pos); |
| 2358 FXSYS_memset(m_WordBuffer, 0, kEndStreamStr.GetLength() + 1); | 2359 FXSYS_memset(m_WordBuffer, 0, kEndStreamStr.GetLength() + 1); |
| 2359 GetNextWord(); | 2360 GetNextWordInternal(); |
| 2360 // Earlier version of PDF specification doesn't require EOL marker before | 2361 // Earlier version of PDF specification doesn't require EOL marker before |
| 2361 // 'endstream' keyword. If keyword 'endstream' follows the bytes in | 2362 // 'endstream' keyword. If keyword 'endstream' follows the bytes in |
| 2362 // specified length, it signals the end of stream. | 2363 // specified length, it signals the end of stream. |
| 2363 if (FXSYS_memcmp(m_WordBuffer, kEndStreamStr.GetPtr(), | 2364 if (FXSYS_memcmp(m_WordBuffer, kEndStreamStr.GetPtr(), |
| 2364 kEndStreamStr.GetLength()) == 0) { | 2365 kEndStreamStr.GetLength()) == 0) { |
| 2365 bSearchForKeyword = FALSE; | 2366 bSearchForKeyword = FALSE; |
| 2366 } | 2367 } |
| 2367 } | 2368 } |
| 2368 if (bSearchForKeyword) { | 2369 if (bSearchForKeyword) { |
| 2369 // If len is not available, len needs to be calculated | 2370 // If len is not available, len needs to be calculated |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2449 len = dest_buf.GetSize(); | 2450 len = dest_buf.GetSize(); |
| 2450 dest_buf.DetachBuffer(); | 2451 dest_buf.DetachBuffer(); |
| 2451 } | 2452 } |
| 2452 } | 2453 } |
| 2453 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); | 2454 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); |
| 2454 if (pContext) { | 2455 if (pContext) { |
| 2455 pContext->m_DataEnd = pContext->m_DataStart + len; | 2456 pContext->m_DataEnd = pContext->m_DataStart + len; |
| 2456 } | 2457 } |
| 2457 streamStartPos = m_Pos; | 2458 streamStartPos = m_Pos; |
| 2458 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); | 2459 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); |
| 2459 GetNextWord(); | 2460 GetNextWordInternal(); |
| 2460 int numMarkers = ReadEOLMarkers(m_Pos); | 2461 int numMarkers = ReadEOLMarkers(m_Pos); |
| 2461 if (m_WordSize == kEndObjStr.GetLength() && numMarkers != 0 && | 2462 if (m_WordSize == kEndObjStr.GetLength() && numMarkers != 0 && |
| 2462 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == | 2463 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == |
| 2463 0) { | 2464 0) { |
| 2464 m_Pos = streamStartPos; | 2465 m_Pos = streamStartPos; |
| 2465 } | 2466 } |
| 2466 return pStream; | 2467 return pStream; |
| 2467 } | 2468 } |
| 2468 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, | 2469 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, |
| 2469 FX_DWORD HeaderOffset) { | 2470 FX_DWORD HeaderOffset) { |
| 2470 FX_Free(m_pFileBuf); | 2471 FX_Free(m_pFileBuf); |
| 2471 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize); | 2472 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize); |
| 2472 m_HeaderOffset = HeaderOffset; | 2473 m_HeaderOffset = HeaderOffset; |
| 2473 m_FileLen = pFileAccess->GetSize(); | 2474 m_FileLen = pFileAccess->GetSize(); |
| 2474 m_Pos = 0; | 2475 m_Pos = 0; |
| 2475 m_pFileAccess = pFileAccess; | 2476 m_pFileAccess = pFileAccess; |
| 2476 m_BufOffset = 0; | 2477 m_BufOffset = 0; |
| 2477 pFileAccess->ReadBlock( | 2478 pFileAccess->ReadBlock( |
| 2478 m_pFileBuf, 0, | 2479 m_pFileBuf, 0, |
| 2479 (size_t)((FX_FILESIZE)m_BufSize > m_FileLen ? m_FileLen : m_BufSize)); | 2480 (size_t)((FX_FILESIZE)m_BufSize > m_FileLen ? m_FileLen : m_BufSize)); |
| 2480 } | 2481 } |
| 2481 int32_t CPDF_SyntaxParser::GetDirectNum() { | 2482 int32_t CPDF_SyntaxParser::GetDirectNum() { |
| 2482 GetNextWord(); | 2483 if (!GetNextWordInternal()) |
| 2483 if (!m_bIsNumber) { | |
| 2484 return 0; | 2484 return 0; |
| 2485 } | 2485 |
| 2486 m_WordBuffer[m_WordSize] = 0; | 2486 m_WordBuffer[m_WordSize] = 0; |
| 2487 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); | 2487 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); |
| 2488 } | 2488 } |
| 2489 | 2489 |
| 2490 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, | 2490 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, |
| 2491 FX_FILESIZE limit, | 2491 FX_FILESIZE limit, |
| 2492 const CFX_ByteStringC& tag, | 2492 const CFX_ByteStringC& tag, |
| 2493 FX_BOOL checkKeyword) { | 2493 FX_BOOL checkKeyword) { |
| 2494 const FX_DWORD taglen = tag.GetLength(); | 2494 const FX_DWORD taglen = tag.GetLength(); |
| 2495 bool bCheckLeft = !PDFCharIsDelimiter(tag[0]) && !PDFCharIsWhitespace(tag[0]); | 2495 bool bCheckLeft = !PDFCharIsDelimiter(tag[0]) && !PDFCharIsWhitespace(tag[0]); |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3609 | 3609 |
| 3610 m_docStatus = PDF_DATAAVAIL_DONE; | 3610 m_docStatus = PDF_DATAAVAIL_DONE; |
| 3611 return TRUE; | 3611 return TRUE; |
| 3612 } | 3612 } |
| 3613 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( | 3613 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( |
| 3614 FX_FILESIZE pos, | 3614 FX_FILESIZE pos, |
| 3615 FX_DWORD objnum, | 3615 FX_DWORD objnum, |
| 3616 CPDF_IndirectObjects* pObjList) { | 3616 CPDF_IndirectObjects* pObjList) { |
| 3617 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 3617 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
| 3618 m_syntaxParser.RestorePos(pos); | 3618 m_syntaxParser.RestorePos(pos); |
| 3619 FX_BOOL bIsNumber; | 3619 bool bIsNumber; |
| 3620 CFX_ByteString word = m_syntaxParser.GetNextWord(bIsNumber); | 3620 CFX_ByteString word = m_syntaxParser.GetNextWord(&bIsNumber); |
| 3621 if (!bIsNumber) { | 3621 if (!bIsNumber) |
| 3622 return NULL; | 3622 return nullptr; |
| 3623 } | 3623 |
| 3624 FX_DWORD parser_objnum = FXSYS_atoi(word); | 3624 FX_DWORD parser_objnum = FXSYS_atoi(word); |
| 3625 if (objnum && parser_objnum != objnum) { | 3625 if (objnum && parser_objnum != objnum) { |
| 3626 return NULL; | 3626 return nullptr; |
| 3627 } | 3627 } |
| 3628 word = m_syntaxParser.GetNextWord(bIsNumber); | 3628 word = m_syntaxParser.GetNextWord(&bIsNumber); |
| 3629 if (!bIsNumber) { | 3629 if (!bIsNumber) |
| 3630 return NULL; | 3630 return nullptr; |
| 3631 } | 3631 |
| 3632 FX_DWORD gennum = FXSYS_atoi(word); | 3632 FX_DWORD gennum = FXSYS_atoi(word); |
| 3633 if (m_syntaxParser.GetKeyword() != "obj") { | 3633 if (m_syntaxParser.GetKeyword() != "obj") { |
| 3634 m_syntaxParser.RestorePos(SavedPos); | 3634 m_syntaxParser.RestorePos(SavedPos); |
| 3635 return NULL; | 3635 return nullptr; |
| 3636 } | 3636 } |
| 3637 CPDF_Object* pObj = | 3637 CPDF_Object* pObj = |
| 3638 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, 0); | 3638 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, 0); |
| 3639 m_syntaxParser.RestorePos(SavedPos); | 3639 m_syntaxParser.RestorePos(SavedPos); |
| 3640 return pObj; | 3640 return pObj; |
| 3641 } | 3641 } |
| 3642 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { | 3642 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { |
| 3643 FX_DWORD req_size = 1024; | 3643 FX_DWORD req_size = 1024; |
| 3644 if (!m_pFileAvail->IsDataAvail(0, req_size)) { | 3644 if (!m_pFileAvail->IsDataAvail(0, req_size)) { |
| 3645 return LinearizationUnknown; | 3645 return LinearizationUnknown; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 3661 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) { | 3661 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) { |
| 3662 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); | 3662 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); |
| 3663 int32_t offset = GetHeaderOffset(file.get()); | 3663 int32_t offset = GetHeaderOffset(file.get()); |
| 3664 if (offset == -1) { | 3664 if (offset == -1) { |
| 3665 m_docStatus = PDF_DATAAVAIL_ERROR; | 3665 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3666 return FALSE; | 3666 return FALSE; |
| 3667 } | 3667 } |
| 3668 m_dwHeaderOffset = offset; | 3668 m_dwHeaderOffset = offset; |
| 3669 m_syntaxParser.InitParser(file.get(), offset); | 3669 m_syntaxParser.InitParser(file.get(), offset); |
| 3670 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 3670 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
| 3671 FX_BOOL bNumber = FALSE; | 3671 bool bNumber; |
| 3672 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); | 3672 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); |
| 3673 if (!bNumber) { | 3673 if (!bNumber) |
| 3674 return FALSE; | 3674 return FALSE; |
| 3675 } | 3675 |
| 3676 FX_DWORD objnum = FXSYS_atoi(wordObjNum); | 3676 FX_DWORD objnum = FXSYS_atoi(wordObjNum); |
| 3677 if (m_pLinearized) { | 3677 if (m_pLinearized) { |
| 3678 m_pLinearized->Release(); | 3678 m_pLinearized->Release(); |
| 3679 m_pLinearized = NULL; | 3679 m_pLinearized = NULL; |
| 3680 } | 3680 } |
| 3681 m_pLinearized = | 3681 m_pLinearized = |
| 3682 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 3682 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); |
| 3683 if (!m_pLinearized) { | 3683 if (!m_pLinearized) { |
| 3684 return FALSE; | 3684 return FALSE; |
| 3685 } | 3685 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 3705 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { | 3705 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { |
| 3706 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 3706 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
| 3707 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 3707 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); |
| 3708 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 3708 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
| 3709 uint8_t buffer[1024]; | 3709 uint8_t buffer[1024]; |
| 3710 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 3710 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
| 3711 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); | 3711 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); |
| 3712 m_syntaxParser.InitParser(file.get(), 0); | 3712 m_syntaxParser.InitParser(file.get(), 0); |
| 3713 m_syntaxParser.RestorePos(dwSize - 1); | 3713 m_syntaxParser.RestorePos(dwSize - 1); |
| 3714 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { | 3714 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { |
| 3715 FX_BOOL bNumber; | 3715 m_syntaxParser.GetNextWord(nullptr); |
| 3716 m_syntaxParser.GetNextWord(bNumber); | 3716 bool bNumber; |
| 3717 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); | 3717 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(&bNumber); |
| 3718 if (!bNumber) { | 3718 if (!bNumber) { |
| 3719 m_docStatus = PDF_DATAAVAIL_ERROR; | 3719 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3720 return FALSE; | 3720 return FALSE; |
| 3721 } | 3721 } |
| 3722 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 3722 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
| 3723 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 3723 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { |
| 3724 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3724 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| 3725 return TRUE; | 3725 return TRUE; |
| 3726 } | 3726 } |
| 3727 m_dwLastXRefOffset = m_dwXRefOffset; | 3727 m_dwLastXRefOffset = m_dwXRefOffset; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 3740 xref_offset = 0; | 3740 xref_offset = 0; |
| 3741 FX_DWORD req_size = | 3741 FX_DWORD req_size = |
| 3742 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 3742 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
| 3743 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 3743 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
| 3744 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 3744 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
| 3745 CFX_BinaryBuf buf(iSize); | 3745 CFX_BinaryBuf buf(iSize); |
| 3746 uint8_t* pBuf = buf.GetBuffer(); | 3746 uint8_t* pBuf = buf.GetBuffer(); |
| 3747 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 3747 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
| 3748 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 3748 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); |
| 3749 m_parser.m_Syntax.InitParser(file.get(), 0); | 3749 m_parser.m_Syntax.InitParser(file.get(), 0); |
| 3750 FX_BOOL bNumber = FALSE; | 3750 bool bNumber; |
| 3751 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); | 3751 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(&bNumber); |
| 3752 if (!bNumber) { | 3752 if (!bNumber) |
| 3753 return -1; | 3753 return -1; |
| 3754 } | 3754 |
| 3755 FX_DWORD objNum = FXSYS_atoi(objnum); | 3755 FX_DWORD objNum = FXSYS_atoi(objnum); |
| 3756 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL); | 3756 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL); |
| 3757 if (!pObj) { | 3757 if (!pObj) { |
| 3758 m_Pos += m_parser.m_Syntax.SavePos(); | 3758 m_Pos += m_parser.m_Syntax.SavePos(); |
| 3759 return 0; | 3759 return 0; |
| 3760 } | 3760 } |
| 3761 CPDF_Dictionary* pDict = pObj->GetDict(); | 3761 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 3762 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); | 3762 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); |
| 3763 if (pName) { | 3763 if (pName) { |
| 3764 if (pName->GetString() == "XRef") { | 3764 if (pName->GetString() == "XRef") { |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4987 if (!m_pLinearizedDict) | 4987 if (!m_pLinearizedDict) |
| 4988 return -1; | 4988 return -1; |
| 4989 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4989 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
| 4990 if (!pRange) | 4990 if (!pRange) |
| 4991 return -1; | 4991 return -1; |
| 4992 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4992 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 4993 if (!pStreamLen) | 4993 if (!pStreamLen) |
| 4994 return -1; | 4994 return -1; |
| 4995 return pStreamLen->GetInteger(); | 4995 return pStreamLen->GetInteger(); |
| 4996 } | 4996 } |
| OLD | NEW |