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 <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 FX_BOOL bXRefRebuilt = FALSE; | 209 FX_BOOL bXRefRebuilt = FALSE; |
210 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { | 210 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { |
211 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); | 211 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); |
212 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), | 212 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), |
213 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 213 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
214 CompareFileSize); | 214 CompareFileSize); |
215 if (!pResult) | 215 if (!pResult) |
216 m_SortedOffset.Add(startxref_offset); | 216 m_SortedOffset.Add(startxref_offset); |
217 | 217 |
218 m_Syntax.GetKeyword(); | 218 m_Syntax.GetKeyword(); |
219 FX_BOOL bNumber; | 219 bool bNumber; |
220 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); | 220 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(&bNumber); |
221 if (!bNumber) | 221 if (!bNumber) |
222 return PDFPARSE_ERROR_FORMAT; | 222 return PDFPARSE_ERROR_FORMAT; |
223 | 223 |
224 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 224 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
225 if (!LoadAllCrossRefV4(m_LastXRefOffset) && | 225 if (!LoadAllCrossRefV4(m_LastXRefOffset) && |
226 !LoadAllCrossRefV5(m_LastXRefOffset)) { | 226 !LoadAllCrossRefV5(m_LastXRefOffset)) { |
227 if (!RebuildCrossRef()) | 227 if (!RebuildCrossRef()) |
228 return PDFPARSE_ERROR_FORMAT; | 228 return PDFPARSE_ERROR_FORMAT; |
229 | 229 |
230 bXRefRebuilt = TRUE; | 230 bXRefRebuilt = TRUE; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 return false; | 516 return false; |
517 | 517 |
518 if (!FindPosInOffsets(pos)) | 518 if (!FindPosInOffsets(pos)) |
519 m_SortedOffset.Add(pos); | 519 m_SortedOffset.Add(pos); |
520 | 520 |
521 if (streampos && !FindPosInOffsets(streampos)) | 521 if (streampos && !FindPosInOffsets(streampos)) |
522 m_SortedOffset.Add(streampos); | 522 m_SortedOffset.Add(streampos); |
523 | 523 |
524 while (1) { | 524 while (1) { |
525 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 525 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
526 FX_BOOL bIsNumber; | 526 bool bIsNumber; |
527 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 527 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
528 if (word.IsEmpty()) | 528 if (word.IsEmpty()) |
529 return false; | 529 return false; |
530 | 530 |
531 if (!bIsNumber) { | 531 if (!bIsNumber) { |
532 m_Syntax.RestorePos(SavedPos); | 532 m_Syntax.RestorePos(SavedPos); |
533 break; | 533 break; |
534 } | 534 } |
535 FX_DWORD start_objnum = FXSYS_atoi(word); | 535 FX_DWORD start_objnum = FXSYS_atoi(word); |
536 if (start_objnum >= kMaxObjectNumber) | 536 if (start_objnum >= kMaxObjectNumber) |
537 return false; | 537 return false; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } else { | 874 } else { |
875 if (pObj->IsStream()) { | 875 if (pObj->IsStream()) { |
876 m_pTrailer = ToDictionary(pTrailer->Clone()); | 876 m_pTrailer = ToDictionary(pTrailer->Clone()); |
877 pObj->Release(); | 877 pObj->Release(); |
878 } else { | 878 } else { |
879 m_pTrailer = pTrailer; | 879 m_pTrailer = pTrailer; |
880 } | 880 } |
881 FX_FILESIZE dwSavePos = m_Syntax.SavePos(); | 881 FX_FILESIZE dwSavePos = m_Syntax.SavePos(); |
882 CFX_ByteString strWord = m_Syntax.GetKeyword(); | 882 CFX_ByteString strWord = m_Syntax.GetKeyword(); |
883 if (!strWord.Compare("startxref")) { | 883 if (!strWord.Compare("startxref")) { |
884 FX_BOOL bNumber = FALSE; | 884 bool bNumber; |
885 CFX_ByteString bsOffset = m_Syntax.GetNextWord(bNumber); | 885 CFX_ByteString bsOffset = |
| 886 m_Syntax.GetNextWord(&bNumber); |
886 if (bNumber) { | 887 if (bNumber) { |
887 m_LastXRefOffset = FXSYS_atoi(bsOffset); | 888 m_LastXRefOffset = FXSYS_atoi(bsOffset); |
888 } | 889 } |
889 } | 890 } |
890 m_Syntax.RestorePos(dwSavePos); | 891 m_Syntax.RestorePos(dwSavePos); |
891 } | 892 } |
892 } else { | 893 } else { |
893 pObj->Release(); | 894 pObj->Release(); |
894 } | 895 } |
895 } | 896 } |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 | 1311 |
1311 if (m_V5Type[objnum] != 1) | 1312 if (m_V5Type[objnum] != 1) |
1312 return; | 1313 return; |
1313 | 1314 |
1314 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1315 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
1315 if (pos == 0) { | 1316 if (pos == 0) { |
1316 return; | 1317 return; |
1317 } | 1318 } |
1318 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1319 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1319 m_Syntax.RestorePos(pos); | 1320 m_Syntax.RestorePos(pos); |
1320 FX_BOOL bIsNumber; | 1321 bool bIsNumber; |
1321 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1322 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
1322 if (!bIsNumber) { | 1323 if (!bIsNumber) { |
1323 m_Syntax.RestorePos(SavedPos); | 1324 m_Syntax.RestorePos(SavedPos); |
1324 return; | 1325 return; |
1325 } | 1326 } |
1326 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1327 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1327 if (parser_objnum && parser_objnum != objnum) { | 1328 if (parser_objnum && parser_objnum != objnum) { |
1328 m_Syntax.RestorePos(SavedPos); | 1329 m_Syntax.RestorePos(SavedPos); |
1329 return; | 1330 return; |
1330 } | 1331 } |
1331 word = m_Syntax.GetNextWord(bIsNumber); | 1332 word = m_Syntax.GetNextWord(&bIsNumber); |
1332 if (!bIsNumber) { | 1333 if (!bIsNumber) { |
1333 m_Syntax.RestorePos(SavedPos); | 1334 m_Syntax.RestorePos(SavedPos); |
1334 return; | 1335 return; |
1335 } | 1336 } |
1336 if (m_Syntax.GetKeyword() != "obj") { | 1337 if (m_Syntax.GetKeyword() != "obj") { |
1337 m_Syntax.RestorePos(SavedPos); | 1338 m_Syntax.RestorePos(SavedPos); |
1338 return; | 1339 return; |
1339 } | 1340 } |
1340 void* pResult = | 1341 void* pResult = |
1341 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 1342 FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
1342 sizeof(FX_FILESIZE), CompareFileSize); | 1343 sizeof(FX_FILESIZE), CompareFileSize); |
1343 if (!pResult) { | 1344 if (!pResult) { |
1344 m_Syntax.RestorePos(SavedPos); | 1345 m_Syntax.RestorePos(SavedPos); |
1345 return; | 1346 return; |
1346 } | 1347 } |
1347 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; | 1348 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; |
1348 FX_BOOL bNextOffValid = FALSE; | 1349 FX_BOOL bNextOffValid = FALSE; |
1349 if (nextoff != pos) { | 1350 if (nextoff != pos) { |
1350 m_Syntax.RestorePos(nextoff); | 1351 m_Syntax.RestorePos(nextoff); |
1351 word = m_Syntax.GetNextWord(bIsNumber); | 1352 word = m_Syntax.GetNextWord(&bIsNumber); |
1352 if (word == "xref") { | 1353 if (word == "xref") { |
1353 bNextOffValid = TRUE; | 1354 bNextOffValid = TRUE; |
1354 } else if (bIsNumber) { | 1355 } else if (bIsNumber) { |
1355 word = m_Syntax.GetNextWord(bIsNumber); | 1356 word = m_Syntax.GetNextWord(&bIsNumber); |
1356 if (bIsNumber && m_Syntax.GetKeyword() == "obj") { | 1357 if (bIsNumber && m_Syntax.GetKeyword() == "obj") { |
1357 bNextOffValid = TRUE; | 1358 bNextOffValid = TRUE; |
1358 } | 1359 } |
1359 } | 1360 } |
1360 } | 1361 } |
1361 if (!bNextOffValid) { | 1362 if (!bNextOffValid) { |
1362 m_Syntax.RestorePos(pos); | 1363 m_Syntax.RestorePos(pos); |
1363 while (1) { | 1364 while (1) { |
1364 if (m_Syntax.GetKeyword() == "endobj") { | 1365 if (m_Syntax.GetKeyword() == "endobj") { |
1365 break; | 1366 break; |
(...skipping 10 matching lines...) Expand all Loading... |
1376 m_Syntax.ReadBlock(pBuffer, size); | 1377 m_Syntax.ReadBlock(pBuffer, size); |
1377 m_Syntax.RestorePos(SavedPos); | 1378 m_Syntax.RestorePos(SavedPos); |
1378 } | 1379 } |
1379 | 1380 |
1380 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, | 1381 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, |
1381 FX_FILESIZE pos, | 1382 FX_FILESIZE pos, |
1382 FX_DWORD objnum, | 1383 FX_DWORD objnum, |
1383 PARSE_CONTEXT* pContext) { | 1384 PARSE_CONTEXT* pContext) { |
1384 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1385 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1385 m_Syntax.RestorePos(pos); | 1386 m_Syntax.RestorePos(pos); |
1386 FX_BOOL bIsNumber; | 1387 bool bIsNumber; |
1387 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1388 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
1388 if (!bIsNumber) { | 1389 if (!bIsNumber) { |
1389 m_Syntax.RestorePos(SavedPos); | 1390 m_Syntax.RestorePos(SavedPos); |
1390 return NULL; | 1391 return NULL; |
1391 } | 1392 } |
1392 FX_FILESIZE objOffset = m_Syntax.SavePos(); | 1393 FX_FILESIZE objOffset = m_Syntax.SavePos(); |
1393 objOffset -= word.GetLength(); | 1394 objOffset -= word.GetLength(); |
1394 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1395 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1395 if (objnum && parser_objnum != objnum) { | 1396 if (objnum && parser_objnum != objnum) { |
1396 m_Syntax.RestorePos(SavedPos); | 1397 m_Syntax.RestorePos(SavedPos); |
1397 return NULL; | 1398 return NULL; |
1398 } | 1399 } |
1399 word = m_Syntax.GetNextWord(bIsNumber); | 1400 word = m_Syntax.GetNextWord(&bIsNumber); |
1400 if (!bIsNumber) { | 1401 if (!bIsNumber) { |
1401 m_Syntax.RestorePos(SavedPos); | 1402 m_Syntax.RestorePos(SavedPos); |
1402 return NULL; | 1403 return NULL; |
1403 } | 1404 } |
1404 FX_DWORD parser_gennum = FXSYS_atoi(word); | 1405 FX_DWORD parser_gennum = FXSYS_atoi(word); |
1405 if (m_Syntax.GetKeyword() != "obj") { | 1406 if (m_Syntax.GetKeyword() != "obj") { |
1406 m_Syntax.RestorePos(SavedPos); | 1407 m_Syntax.RestorePos(SavedPos); |
1407 return NULL; | 1408 return NULL; |
1408 } | 1409 } |
1409 CPDF_Object* pObj = | 1410 CPDF_Object* pObj = |
(...skipping 13 matching lines...) Expand all Loading... |
1423 return pObj; | 1424 return pObj; |
1424 } | 1425 } |
1425 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 1426 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( |
1426 CPDF_IndirectObjects* pObjList, | 1427 CPDF_IndirectObjects* pObjList, |
1427 FX_FILESIZE pos, | 1428 FX_FILESIZE pos, |
1428 FX_DWORD objnum, | 1429 FX_DWORD objnum, |
1429 PARSE_CONTEXT* pContext, | 1430 PARSE_CONTEXT* pContext, |
1430 FX_FILESIZE* pResultPos) { | 1431 FX_FILESIZE* pResultPos) { |
1431 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1432 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1432 m_Syntax.RestorePos(pos); | 1433 m_Syntax.RestorePos(pos); |
1433 FX_BOOL bIsNumber; | 1434 bool bIsNumber; |
1434 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1435 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
1435 if (!bIsNumber) { | 1436 if (!bIsNumber) { |
1436 m_Syntax.RestorePos(SavedPos); | 1437 m_Syntax.RestorePos(SavedPos); |
1437 return NULL; | 1438 return NULL; |
1438 } | 1439 } |
1439 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1440 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1440 if (objnum && parser_objnum != objnum) { | 1441 if (objnum && parser_objnum != objnum) { |
1441 m_Syntax.RestorePos(SavedPos); | 1442 m_Syntax.RestorePos(SavedPos); |
1442 return NULL; | 1443 return NULL; |
1443 } | 1444 } |
1444 word = m_Syntax.GetNextWord(bIsNumber); | 1445 word = m_Syntax.GetNextWord(&bIsNumber); |
1445 if (!bIsNumber) { | 1446 if (!bIsNumber) { |
1446 m_Syntax.RestorePos(SavedPos); | 1447 m_Syntax.RestorePos(SavedPos); |
1447 return NULL; | 1448 return NULL; |
1448 } | 1449 } |
1449 FX_DWORD gennum = FXSYS_atoi(word); | 1450 FX_DWORD gennum = FXSYS_atoi(word); |
1450 if (m_Syntax.GetKeyword() != "obj") { | 1451 if (m_Syntax.GetKeyword() != "obj") { |
1451 m_Syntax.RestorePos(SavedPos); | 1452 m_Syntax.RestorePos(SavedPos); |
1452 return NULL; | 1453 return NULL; |
1453 } | 1454 } |
1454 CPDF_Object* pObj = | 1455 CPDF_Object* pObj = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 return; | 1497 return; |
1497 } | 1498 } |
1498 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); | 1499 m_Syntax.m_pCryptoHandler.reset(pSecurityHandler->CreateCryptoHandler()); |
1499 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 1500 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); |
1500 } | 1501 } |
1501 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, | 1502 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, |
1502 FX_DWORD offset) { | 1503 FX_DWORD offset) { |
1503 m_Syntax.InitParser(pFileAccess, offset); | 1504 m_Syntax.InitParser(pFileAccess, offset); |
1504 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); | 1505 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); |
1505 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1506 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1506 FX_BOOL bIsNumber; | 1507 bool bIsNumber; |
1507 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1508 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
1508 if (!bIsNumber) { | 1509 if (!bIsNumber) { |
1509 return FALSE; | 1510 return FALSE; |
1510 } | 1511 } |
1511 FX_DWORD objnum = FXSYS_atoi(word); | 1512 FX_DWORD objnum = FXSYS_atoi(word); |
1512 word = m_Syntax.GetNextWord(bIsNumber); | 1513 word = m_Syntax.GetNextWord(&bIsNumber); |
1513 if (!bIsNumber) { | 1514 if (!bIsNumber) { |
1514 return FALSE; | 1515 return FALSE; |
1515 } | 1516 } |
1516 FX_DWORD gennum = FXSYS_atoi(word); | 1517 FX_DWORD gennum = FXSYS_atoi(word); |
1517 if (m_Syntax.GetKeyword() != "obj") { | 1518 if (m_Syntax.GetKeyword() != "obj") { |
1518 m_Syntax.RestorePos(SavedPos); | 1519 m_Syntax.RestorePos(SavedPos); |
1519 return FALSE; | 1520 return FALSE; |
1520 } | 1521 } |
1521 m_pLinearized = m_Syntax.GetObject(nullptr, objnum, gennum, nullptr, true); | 1522 m_pLinearized = m_Syntax.GetObject(nullptr, objnum, gennum, nullptr, true); |
1522 if (!m_pLinearized) { | 1523 if (!m_pLinearized) { |
1523 return FALSE; | 1524 return FALSE; |
1524 } | 1525 } |
1525 | 1526 |
1526 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1527 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
1527 if (pDict && pDict->GetElement("Linearized")) { | 1528 if (pDict && pDict->GetElement("Linearized")) { |
1528 m_Syntax.GetNextWord(bIsNumber); | 1529 m_Syntax.GetNextWord(nullptr); |
1529 | 1530 |
1530 CPDF_Object* pLen = pDict->GetElement("L"); | 1531 CPDF_Object* pLen = pDict->GetElement("L"); |
1531 if (!pLen) { | 1532 if (!pLen) { |
1532 m_pLinearized->Release(); | 1533 m_pLinearized->Release(); |
1533 m_pLinearized = NULL; | 1534 m_pLinearized = NULL; |
1534 return FALSE; | 1535 return FALSE; |
1535 } | 1536 } |
1536 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { | 1537 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { |
1537 return FALSE; | 1538 return FALSE; |
1538 } | 1539 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 return TRUE; | 1773 return TRUE; |
1773 } | 1774 } |
1774 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) { | 1775 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) { |
1775 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { | 1776 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { |
1776 return FALSE; | 1777 return FALSE; |
1777 } | 1778 } |
1778 m_Pos += size; | 1779 m_Pos += size; |
1779 return TRUE; | 1780 return TRUE; |
1780 } | 1781 } |
1781 | 1782 |
1782 void CPDF_SyntaxParser::GetNextWord() { | 1783 void CPDF_SyntaxParser::GetNextWordInternal(bool* bIsNumber) { |
1783 m_WordSize = 0; | 1784 m_WordSize = 0; |
1784 m_bIsNumber = TRUE; | 1785 if (bIsNumber) |
| 1786 *bIsNumber = true; |
1785 uint8_t ch; | 1787 uint8_t ch; |
1786 if (!GetNextChar(ch)) { | 1788 if (!GetNextChar(ch)) { |
1787 return; | 1789 return; |
1788 } | 1790 } |
1789 while (1) { | 1791 while (1) { |
1790 while (PDFCharIsWhitespace(ch)) { | 1792 while (PDFCharIsWhitespace(ch)) { |
1791 if (!GetNextChar(ch)) | 1793 if (!GetNextChar(ch)) |
1792 return; | 1794 return; |
1793 } | 1795 } |
1794 if (ch != '%') | 1796 if (ch != '%') |
1795 break; | 1797 break; |
1796 | 1798 |
1797 while (1) { | 1799 while (1) { |
1798 if (!GetNextChar(ch)) | 1800 if (!GetNextChar(ch)) |
1799 return; | 1801 return; |
1800 if (PDFCharIsLineEnding(ch)) | 1802 if (PDFCharIsLineEnding(ch)) |
1801 break; | 1803 break; |
1802 } | 1804 } |
1803 } | 1805 } |
1804 | 1806 |
1805 if (PDFCharIsDelimiter(ch)) { | 1807 if (PDFCharIsDelimiter(ch)) { |
1806 m_bIsNumber = FALSE; | 1808 if (bIsNumber) |
| 1809 *bIsNumber = false; |
1807 m_WordBuffer[m_WordSize++] = ch; | 1810 m_WordBuffer[m_WordSize++] = ch; |
1808 if (ch == '/') { | 1811 if (ch == '/') { |
1809 while (1) { | 1812 while (1) { |
1810 if (!GetNextChar(ch)) | 1813 if (!GetNextChar(ch)) |
1811 return; | 1814 return; |
1812 | 1815 |
1813 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { | 1816 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { |
1814 m_Pos--; | 1817 m_Pos--; |
1815 return; | 1818 return; |
1816 } | 1819 } |
(...skipping 17 matching lines...) Expand all Loading... |
1834 m_Pos--; | 1837 m_Pos--; |
1835 } | 1838 } |
1836 return; | 1839 return; |
1837 } | 1840 } |
1838 | 1841 |
1839 while (1) { | 1842 while (1) { |
1840 if (m_WordSize < sizeof(m_WordBuffer) - 1) | 1843 if (m_WordSize < sizeof(m_WordBuffer) - 1) |
1841 m_WordBuffer[m_WordSize++] = ch; | 1844 m_WordBuffer[m_WordSize++] = ch; |
1842 | 1845 |
1843 if (!PDFCharIsNumeric(ch)) | 1846 if (!PDFCharIsNumeric(ch)) |
1844 m_bIsNumber = FALSE; | 1847 if (bIsNumber) |
| 1848 *bIsNumber = false; |
1845 if (!GetNextChar(ch)) | 1849 if (!GetNextChar(ch)) |
1846 return; | 1850 return; |
1847 | 1851 |
1848 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { | 1852 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { |
1849 m_Pos--; | 1853 m_Pos--; |
1850 break; | 1854 break; |
1851 } | 1855 } |
1852 } | 1856 } |
1853 } | 1857 } |
| 1858 |
1854 CFX_ByteString CPDF_SyntaxParser::ReadString() { | 1859 CFX_ByteString CPDF_SyntaxParser::ReadString() { |
1855 uint8_t ch; | 1860 uint8_t ch; |
1856 if (!GetNextChar(ch)) { | 1861 if (!GetNextChar(ch)) { |
1857 return CFX_ByteString(); | 1862 return CFX_ByteString(); |
1858 } | 1863 } |
1859 CFX_ByteTextBuf buf; | 1864 CFX_ByteTextBuf buf; |
1860 int32_t parlevel = 0; | 1865 int32_t parlevel = 0; |
1861 int32_t status = 0, iEscCode = 0; | 1866 int32_t status = 0, iEscCode = 0; |
1862 while (1) { | 1867 while (1) { |
1863 switch (status) { | 1868 switch (status) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 while (1) { | 2006 while (1) { |
2002 if (!GetNextChar(ch)) | 2007 if (!GetNextChar(ch)) |
2003 return; | 2008 return; |
2004 if (PDFCharIsLineEnding(ch)) | 2009 if (PDFCharIsLineEnding(ch)) |
2005 break; | 2010 break; |
2006 } | 2011 } |
2007 } | 2012 } |
2008 m_Pos--; | 2013 m_Pos--; |
2009 } | 2014 } |
2010 | 2015 |
2011 CFX_ByteString CPDF_SyntaxParser::GetNextWord(FX_BOOL& bIsNumber) { | 2016 CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool* bIsNumber) { |
2012 GetNextWord(); | 2017 GetNextWordInternal(bIsNumber); |
2013 bIsNumber = m_bIsNumber; | 2018 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
2014 return CFX_ByteString(m_WordBuffer, m_WordSize); | |
2015 } | 2019 } |
| 2020 |
2016 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { | 2021 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { |
2017 FX_BOOL dummy; | 2022 return GetNextWord(nullptr); |
2018 return GetNextWord(dummy); | |
2019 } | 2023 } |
| 2024 |
2020 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, | 2025 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, |
2021 FX_DWORD objnum, | 2026 FX_DWORD objnum, |
2022 FX_DWORD gennum, | 2027 FX_DWORD gennum, |
2023 PARSE_CONTEXT* pContext, | 2028 PARSE_CONTEXT* pContext, |
2024 FX_BOOL bDecrypt) { | 2029 FX_BOOL bDecrypt) { |
2025 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2030 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2026 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2031 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2027 return NULL; | 2032 return NULL; |
2028 } | 2033 } |
2029 FX_FILESIZE SavedPos = m_Pos; | 2034 FX_FILESIZE SavedPos = m_Pos; |
2030 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2035 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
2031 FX_BOOL bIsNumber; | 2036 bool bIsNumber; |
2032 CFX_ByteString word = GetNextWord(bIsNumber); | 2037 CFX_ByteString word = GetNextWord(&bIsNumber); |
2033 if (word.GetLength() == 0) { | 2038 if (word.GetLength() == 0) { |
2034 if (bTypeOnly) | 2039 if (bTypeOnly) |
2035 return (CPDF_Object*)PDFOBJ_INVALID; | 2040 return (CPDF_Object*)PDFOBJ_INVALID; |
2036 return NULL; | 2041 return NULL; |
2037 } | 2042 } |
2038 if (bIsNumber) { | 2043 if (bIsNumber) { |
2039 FX_FILESIZE SavedPos = m_Pos; | 2044 FX_FILESIZE SavedPos = m_Pos; |
2040 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2045 CFX_ByteString nextword = GetNextWord(&bIsNumber); |
2041 if (bIsNumber) { | 2046 if (bIsNumber) { |
2042 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 2047 CFX_ByteString nextword2 = GetNextWord(nullptr); |
2043 if (nextword2 == "R") { | 2048 if (nextword2 == "R") { |
2044 FX_DWORD objnum = FXSYS_atoi(word); | 2049 FX_DWORD objnum = FXSYS_atoi(word); |
2045 if (bTypeOnly) | 2050 if (bTypeOnly) |
2046 return (CPDF_Object*)PDFOBJ_REFERENCE; | 2051 return (CPDF_Object*)PDFOBJ_REFERENCE; |
2047 return new CPDF_Reference(pObjList, objnum); | 2052 return new CPDF_Reference(pObjList, objnum); |
2048 } | 2053 } |
2049 } | 2054 } |
2050 m_Pos = SavedPos; | 2055 m_Pos = SavedPos; |
2051 if (bTypeOnly) | 2056 if (bTypeOnly) |
2052 return (CPDF_Object*)PDFOBJ_NUMBER; | 2057 return (CPDF_Object*)PDFOBJ_NUMBER; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2101 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2106 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
2102 | 2107 |
2103 if (pContext) | 2108 if (pContext) |
2104 pContext->m_DictStart = SavedPos; | 2109 pContext->m_DictStart = SavedPos; |
2105 | 2110 |
2106 int32_t nKeys = 0; | 2111 int32_t nKeys = 0; |
2107 FX_FILESIZE dwSignValuePos = 0; | 2112 FX_FILESIZE dwSignValuePos = 0; |
2108 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 2113 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
2109 new CPDF_Dictionary); | 2114 new CPDF_Dictionary); |
2110 while (1) { | 2115 while (1) { |
2111 FX_BOOL bIsNumber; | 2116 CFX_ByteString key = GetNextWord(nullptr); |
2112 CFX_ByteString key = GetNextWord(bIsNumber); | |
2113 if (key.IsEmpty()) | 2117 if (key.IsEmpty()) |
2114 return nullptr; | 2118 return nullptr; |
2115 | 2119 |
2116 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 2120 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
2117 if (key == ">>") | 2121 if (key == ">>") |
2118 break; | 2122 break; |
2119 | 2123 |
2120 if (key == "endobj") { | 2124 if (key == "endobj") { |
2121 m_Pos = SavedPos; | 2125 m_Pos = SavedPos; |
2122 break; | 2126 break; |
(...skipping 30 matching lines...) Expand all Loading... |
2153 pDict->SetAt("Contents", pObj); | 2157 pDict->SetAt("Contents", pObj); |
2154 m_Pos = dwSavePos; | 2158 m_Pos = dwSavePos; |
2155 } | 2159 } |
2156 if (pContext) { | 2160 if (pContext) { |
2157 pContext->m_DictEnd = m_Pos; | 2161 pContext->m_DictEnd = m_Pos; |
2158 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2162 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2159 return pDict.release(); | 2163 return pDict.release(); |
2160 } | 2164 } |
2161 } | 2165 } |
2162 FX_FILESIZE SavedPos = m_Pos; | 2166 FX_FILESIZE SavedPos = m_Pos; |
2163 FX_BOOL bIsNumber; | 2167 CFX_ByteString nextword = GetNextWord(nullptr); |
2164 CFX_ByteString nextword = GetNextWord(bIsNumber); | |
2165 if (nextword != "stream") { | 2168 if (nextword != "stream") { |
2166 m_Pos = SavedPos; | 2169 m_Pos = SavedPos; |
2167 return pDict.release(); | 2170 return pDict.release(); |
2168 } | 2171 } |
2169 | 2172 |
2170 return ReadStream(pDict.release(), pContext, objnum, gennum); | 2173 return ReadStream(pDict.release(), pContext, objnum, gennum); |
2171 } | 2174 } |
2172 if (word == ">>") { | 2175 if (word == ">>") { |
2173 m_Pos = SavedPos; | 2176 m_Pos = SavedPos; |
2174 return nullptr; | 2177 return nullptr; |
2175 } | 2178 } |
2176 if (bTypeOnly) | 2179 if (bTypeOnly) |
2177 return (CPDF_Object*)PDFOBJ_INVALID; | 2180 return (CPDF_Object*)PDFOBJ_INVALID; |
2178 | 2181 |
2179 return nullptr; | 2182 return nullptr; |
2180 } | 2183 } |
2181 | 2184 |
2182 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( | 2185 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( |
2183 CPDF_IndirectObjects* pObjList, | 2186 CPDF_IndirectObjects* pObjList, |
2184 FX_DWORD objnum, | 2187 FX_DWORD objnum, |
2185 FX_DWORD gennum, | 2188 FX_DWORD gennum, |
2186 PARSE_CONTEXT* pContext) { | 2189 PARSE_CONTEXT* pContext) { |
2187 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2190 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2188 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2191 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2189 return NULL; | 2192 return NULL; |
2190 } | 2193 } |
2191 FX_FILESIZE SavedPos = m_Pos; | 2194 FX_FILESIZE SavedPos = m_Pos; |
2192 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2195 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
2193 FX_BOOL bIsNumber; | 2196 bool bIsNumber; |
2194 CFX_ByteString word = GetNextWord(bIsNumber); | 2197 CFX_ByteString word = GetNextWord(&bIsNumber); |
2195 if (word.GetLength() == 0) { | 2198 if (word.GetLength() == 0) { |
2196 if (bTypeOnly) | 2199 if (bTypeOnly) |
2197 return (CPDF_Object*)PDFOBJ_INVALID; | 2200 return (CPDF_Object*)PDFOBJ_INVALID; |
2198 return nullptr; | 2201 return nullptr; |
2199 } | 2202 } |
2200 if (bIsNumber) { | 2203 if (bIsNumber) { |
2201 FX_FILESIZE SavedPos = m_Pos; | 2204 FX_FILESIZE SavedPos = m_Pos; |
2202 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2205 CFX_ByteString nextword = GetNextWord(&bIsNumber); |
2203 if (bIsNumber) { | 2206 if (bIsNumber) { |
2204 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 2207 CFX_ByteString nextword2 = GetNextWord(nullptr); |
2205 if (nextword2 == "R") { | 2208 if (nextword2 == "R") { |
2206 if (bTypeOnly) | 2209 if (bTypeOnly) |
2207 return (CPDF_Object*)PDFOBJ_REFERENCE; | 2210 return (CPDF_Object*)PDFOBJ_REFERENCE; |
2208 FX_DWORD objnum = FXSYS_atoi(word); | 2211 FX_DWORD objnum = FXSYS_atoi(word); |
2209 return new CPDF_Reference(pObjList, objnum); | 2212 return new CPDF_Reference(pObjList, objnum); |
2210 } | 2213 } |
2211 } | 2214 } |
2212 m_Pos = SavedPos; | 2215 m_Pos = SavedPos; |
2213 if (bTypeOnly) | 2216 if (bTypeOnly) |
2214 return (CPDF_Object*)PDFOBJ_NUMBER; | 2217 return (CPDF_Object*)PDFOBJ_NUMBER; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 } | 2262 } |
2260 if (word == "<<") { | 2263 if (word == "<<") { |
2261 if (bTypeOnly) | 2264 if (bTypeOnly) |
2262 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2265 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
2263 if (pContext) | 2266 if (pContext) |
2264 pContext->m_DictStart = SavedPos; | 2267 pContext->m_DictStart = SavedPos; |
2265 | 2268 |
2266 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 2269 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
2267 new CPDF_Dictionary); | 2270 new CPDF_Dictionary); |
2268 while (1) { | 2271 while (1) { |
2269 FX_BOOL bIsNumber; | |
2270 FX_FILESIZE SavedPos = m_Pos; | 2272 FX_FILESIZE SavedPos = m_Pos; |
2271 CFX_ByteString key = GetNextWord(bIsNumber); | 2273 CFX_ByteString key = GetNextWord(nullptr); |
2272 if (key.IsEmpty()) | 2274 if (key.IsEmpty()) |
2273 return nullptr; | 2275 return nullptr; |
2274 | 2276 |
2275 if (key == ">>") | 2277 if (key == ">>") |
2276 break; | 2278 break; |
2277 | 2279 |
2278 if (key == "endobj") { | 2280 if (key == "endobj") { |
2279 m_Pos = SavedPos; | 2281 m_Pos = SavedPos; |
2280 break; | 2282 break; |
2281 } | 2283 } |
(...skipping 14 matching lines...) Expand all Loading... |
2296 obj.release()); | 2298 obj.release()); |
2297 } | 2299 } |
2298 } | 2300 } |
2299 if (pContext) { | 2301 if (pContext) { |
2300 pContext->m_DictEnd = m_Pos; | 2302 pContext->m_DictEnd = m_Pos; |
2301 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2303 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2302 return pDict.release(); | 2304 return pDict.release(); |
2303 } | 2305 } |
2304 } | 2306 } |
2305 FX_FILESIZE SavedPos = m_Pos; | 2307 FX_FILESIZE SavedPos = m_Pos; |
2306 FX_BOOL bIsNumber; | 2308 CFX_ByteString nextword = GetNextWord(nullptr); |
2307 CFX_ByteString nextword = GetNextWord(bIsNumber); | |
2308 if (nextword != "stream") { | 2309 if (nextword != "stream") { |
2309 m_Pos = SavedPos; | 2310 m_Pos = SavedPos; |
2310 return pDict.release(); | 2311 return pDict.release(); |
2311 } | 2312 } |
2312 | 2313 |
2313 return ReadStream(pDict.release(), pContext, objnum, gennum); | 2314 return ReadStream(pDict.release(), pContext, objnum, gennum); |
2314 } | 2315 } |
2315 if (word == ">>") { | 2316 if (word == ">>") { |
2316 m_Pos = SavedPos; | 2317 m_Pos = SavedPos; |
2317 return nullptr; | 2318 return nullptr; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 if (!pCryptoHandler) { | 2362 if (!pCryptoHandler) { |
2362 FX_BOOL bSearchForKeyword = TRUE; | 2363 FX_BOOL bSearchForKeyword = TRUE; |
2363 if (len >= 0) { | 2364 if (len >= 0) { |
2364 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; | 2365 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; |
2365 pos += len; | 2366 pos += len; |
2366 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { | 2367 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { |
2367 m_Pos = pos.ValueOrDie(); | 2368 m_Pos = pos.ValueOrDie(); |
2368 } | 2369 } |
2369 m_Pos += ReadEOLMarkers(m_Pos); | 2370 m_Pos += ReadEOLMarkers(m_Pos); |
2370 FXSYS_memset(m_WordBuffer, 0, kEndStreamStr.GetLength() + 1); | 2371 FXSYS_memset(m_WordBuffer, 0, kEndStreamStr.GetLength() + 1); |
2371 GetNextWord(); | 2372 GetNextWordInternal(nullptr); |
2372 // Earlier version of PDF specification doesn't require EOL marker before | 2373 // Earlier version of PDF specification doesn't require EOL marker before |
2373 // 'endstream' keyword. If keyword 'endstream' follows the bytes in | 2374 // 'endstream' keyword. If keyword 'endstream' follows the bytes in |
2374 // specified length, it signals the end of stream. | 2375 // specified length, it signals the end of stream. |
2375 if (FXSYS_memcmp(m_WordBuffer, kEndStreamStr.GetPtr(), | 2376 if (FXSYS_memcmp(m_WordBuffer, kEndStreamStr.GetPtr(), |
2376 kEndStreamStr.GetLength()) == 0) { | 2377 kEndStreamStr.GetLength()) == 0) { |
2377 bSearchForKeyword = FALSE; | 2378 bSearchForKeyword = FALSE; |
2378 } | 2379 } |
2379 } | 2380 } |
2380 if (bSearchForKeyword) { | 2381 if (bSearchForKeyword) { |
2381 // If len is not available, len needs to be calculated | 2382 // If len is not available, len needs to be calculated |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 len = dest_buf.GetSize(); | 2462 len = dest_buf.GetSize(); |
2462 dest_buf.DetachBuffer(); | 2463 dest_buf.DetachBuffer(); |
2463 } | 2464 } |
2464 } | 2465 } |
2465 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); | 2466 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); |
2466 if (pContext) { | 2467 if (pContext) { |
2467 pContext->m_DataEnd = pContext->m_DataStart + len; | 2468 pContext->m_DataEnd = pContext->m_DataStart + len; |
2468 } | 2469 } |
2469 streamStartPos = m_Pos; | 2470 streamStartPos = m_Pos; |
2470 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); | 2471 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); |
2471 GetNextWord(); | 2472 GetNextWordInternal(nullptr); |
2472 int numMarkers = ReadEOLMarkers(m_Pos); | 2473 int numMarkers = ReadEOLMarkers(m_Pos); |
2473 if (m_WordSize == kEndObjStr.GetLength() && numMarkers != 0 && | 2474 if (m_WordSize == kEndObjStr.GetLength() && numMarkers != 0 && |
2474 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == | 2475 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == |
2475 0) { | 2476 0) { |
2476 m_Pos = streamStartPos; | 2477 m_Pos = streamStartPos; |
2477 } | 2478 } |
2478 return pStream; | 2479 return pStream; |
2479 } | 2480 } |
2480 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, | 2481 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, |
2481 FX_DWORD HeaderOffset) { | 2482 FX_DWORD HeaderOffset) { |
2482 FX_Free(m_pFileBuf); | 2483 FX_Free(m_pFileBuf); |
2483 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize); | 2484 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize); |
2484 m_HeaderOffset = HeaderOffset; | 2485 m_HeaderOffset = HeaderOffset; |
2485 m_FileLen = pFileAccess->GetSize(); | 2486 m_FileLen = pFileAccess->GetSize(); |
2486 m_Pos = 0; | 2487 m_Pos = 0; |
2487 m_pFileAccess = pFileAccess; | 2488 m_pFileAccess = pFileAccess; |
2488 m_BufOffset = 0; | 2489 m_BufOffset = 0; |
2489 pFileAccess->ReadBlock( | 2490 pFileAccess->ReadBlock( |
2490 m_pFileBuf, 0, | 2491 m_pFileBuf, 0, |
2491 (size_t)((FX_FILESIZE)m_BufSize > m_FileLen ? m_FileLen : m_BufSize)); | 2492 (size_t)((FX_FILESIZE)m_BufSize > m_FileLen ? m_FileLen : m_BufSize)); |
2492 } | 2493 } |
2493 int32_t CPDF_SyntaxParser::GetDirectNum() { | 2494 int32_t CPDF_SyntaxParser::GetDirectNum() { |
2494 GetNextWord(); | 2495 bool bIsNumber; |
2495 if (!m_bIsNumber) { | 2496 GetNextWordInternal(&bIsNumber); |
| 2497 if (!bIsNumber) |
2496 return 0; | 2498 return 0; |
2497 } | 2499 |
2498 m_WordBuffer[m_WordSize] = 0; | 2500 m_WordBuffer[m_WordSize] = 0; |
2499 return FXSYS_atoi(reinterpret_cast<const FX_CHAR*>(m_WordBuffer)); | 2501 return FXSYS_atoi(reinterpret_cast<const FX_CHAR*>(m_WordBuffer)); |
2500 } | 2502 } |
2501 | 2503 |
2502 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, | 2504 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, |
2503 FX_FILESIZE limit, | 2505 FX_FILESIZE limit, |
2504 const CFX_ByteStringC& tag, | 2506 const CFX_ByteStringC& tag, |
2505 FX_BOOL checkKeyword) { | 2507 FX_BOOL checkKeyword) { |
2506 const FX_DWORD taglen = tag.GetLength(); | 2508 const FX_DWORD taglen = tag.GetLength(); |
2507 bool bCheckLeft = !PDFCharIsDelimiter(tag[0]) && !PDFCharIsWhitespace(tag[0]); | 2509 bool bCheckLeft = !PDFCharIsDelimiter(tag[0]) && !PDFCharIsWhitespace(tag[0]); |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3616 | 3618 |
3617 m_docStatus = PDF_DATAAVAIL_DONE; | 3619 m_docStatus = PDF_DATAAVAIL_DONE; |
3618 return TRUE; | 3620 return TRUE; |
3619 } | 3621 } |
3620 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( | 3622 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( |
3621 FX_FILESIZE pos, | 3623 FX_FILESIZE pos, |
3622 FX_DWORD objnum, | 3624 FX_DWORD objnum, |
3623 CPDF_IndirectObjects* pObjList) { | 3625 CPDF_IndirectObjects* pObjList) { |
3624 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 3626 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
3625 m_syntaxParser.RestorePos(pos); | 3627 m_syntaxParser.RestorePos(pos); |
3626 FX_BOOL bIsNumber; | 3628 bool bIsNumber; |
3627 CFX_ByteString word = m_syntaxParser.GetNextWord(bIsNumber); | 3629 CFX_ByteString word = m_syntaxParser.GetNextWord(&bIsNumber); |
3628 if (!bIsNumber) { | 3630 if (!bIsNumber) |
3629 return NULL; | 3631 return nullptr; |
3630 } | 3632 |
3631 FX_DWORD parser_objnum = FXSYS_atoi(word); | 3633 FX_DWORD parser_objnum = FXSYS_atoi(word); |
3632 if (objnum && parser_objnum != objnum) { | 3634 if (objnum && parser_objnum != objnum) |
3633 return NULL; | 3635 return nullptr; |
3634 } | 3636 |
3635 word = m_syntaxParser.GetNextWord(bIsNumber); | 3637 word = m_syntaxParser.GetNextWord(&bIsNumber); |
3636 if (!bIsNumber) { | 3638 if (!bIsNumber) |
3637 return NULL; | 3639 return nullptr; |
3638 } | 3640 |
3639 FX_DWORD gennum = FXSYS_atoi(word); | 3641 FX_DWORD gennum = FXSYS_atoi(word); |
3640 if (m_syntaxParser.GetKeyword() != "obj") { | 3642 if (m_syntaxParser.GetKeyword() != "obj") { |
3641 m_syntaxParser.RestorePos(SavedPos); | 3643 m_syntaxParser.RestorePos(SavedPos); |
3642 return NULL; | 3644 return nullptr; |
3643 } | 3645 } |
3644 CPDF_Object* pObj = | 3646 CPDF_Object* pObj = |
3645 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, nullptr, true); | 3647 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, nullptr, true); |
3646 m_syntaxParser.RestorePos(SavedPos); | 3648 m_syntaxParser.RestorePos(SavedPos); |
3647 return pObj; | 3649 return pObj; |
3648 } | 3650 } |
3649 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { | 3651 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { |
3650 FX_DWORD req_size = 1024; | 3652 FX_DWORD req_size = 1024; |
3651 if (!m_pFileAvail->IsDataAvail(0, req_size)) { | 3653 if (!m_pFileAvail->IsDataAvail(0, req_size)) { |
3652 return LinearizationUnknown; | 3654 return LinearizationUnknown; |
(...skipping 15 matching lines...) Expand all Loading... |
3668 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) { | 3670 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) { |
3669 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); | 3671 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); |
3670 int32_t offset = GetHeaderOffset(file.get()); | 3672 int32_t offset = GetHeaderOffset(file.get()); |
3671 if (offset == -1) { | 3673 if (offset == -1) { |
3672 m_docStatus = PDF_DATAAVAIL_ERROR; | 3674 m_docStatus = PDF_DATAAVAIL_ERROR; |
3673 return FALSE; | 3675 return FALSE; |
3674 } | 3676 } |
3675 m_dwHeaderOffset = offset; | 3677 m_dwHeaderOffset = offset; |
3676 m_syntaxParser.InitParser(file.get(), offset); | 3678 m_syntaxParser.InitParser(file.get(), offset); |
3677 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 3679 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
3678 FX_BOOL bNumber = FALSE; | 3680 bool bNumber; |
3679 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); | 3681 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); |
3680 if (!bNumber) { | 3682 if (!bNumber) |
3681 return FALSE; | 3683 return FALSE; |
3682 } | 3684 |
3683 FX_DWORD objnum = FXSYS_atoi(wordObjNum); | 3685 FX_DWORD objnum = FXSYS_atoi(wordObjNum); |
3684 if (m_pLinearized) { | 3686 if (m_pLinearized) { |
3685 m_pLinearized->Release(); | 3687 m_pLinearized->Release(); |
3686 m_pLinearized = NULL; | 3688 m_pLinearized = NULL; |
3687 } | 3689 } |
3688 m_pLinearized = | 3690 m_pLinearized = |
3689 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 3691 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); |
3690 if (!m_pLinearized) { | 3692 if (!m_pLinearized) { |
3691 return FALSE; | 3693 return FALSE; |
3692 } | 3694 } |
(...skipping 19 matching lines...) Expand all Loading... |
3712 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { | 3714 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { |
3713 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 3715 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
3714 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 3716 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); |
3715 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 3717 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
3716 uint8_t buffer[1024]; | 3718 uint8_t buffer[1024]; |
3717 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 3719 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
3718 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); | 3720 ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, FALSE)); |
3719 m_syntaxParser.InitParser(file.get(), 0); | 3721 m_syntaxParser.InitParser(file.get(), 0); |
3720 m_syntaxParser.RestorePos(dwSize - 1); | 3722 m_syntaxParser.RestorePos(dwSize - 1); |
3721 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { | 3723 if (m_syntaxParser.SearchWord("startxref", TRUE, FALSE, dwSize)) { |
3722 FX_BOOL bNumber; | 3724 m_syntaxParser.GetNextWord(nullptr); |
3723 m_syntaxParser.GetNextWord(bNumber); | 3725 bool bNumber; |
3724 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); | 3726 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(&bNumber); |
3725 if (!bNumber) { | 3727 if (!bNumber) { |
3726 m_docStatus = PDF_DATAAVAIL_ERROR; | 3728 m_docStatus = PDF_DATAAVAIL_ERROR; |
3727 return FALSE; | 3729 return FALSE; |
3728 } | 3730 } |
3729 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 3731 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
3730 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 3732 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { |
3731 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3733 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3732 return TRUE; | 3734 return TRUE; |
3733 } | 3735 } |
3734 m_dwLastXRefOffset = m_dwXRefOffset; | 3736 m_dwLastXRefOffset = m_dwXRefOffset; |
(...skipping 12 matching lines...) Expand all Loading... |
3747 xref_offset = 0; | 3749 xref_offset = 0; |
3748 FX_DWORD req_size = | 3750 FX_DWORD req_size = |
3749 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 3751 (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
3750 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 3752 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
3751 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 3753 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
3752 CFX_BinaryBuf buf(iSize); | 3754 CFX_BinaryBuf buf(iSize); |
3753 uint8_t* pBuf = buf.GetBuffer(); | 3755 uint8_t* pBuf = buf.GetBuffer(); |
3754 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 3756 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
3755 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 3757 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); |
3756 m_parser.m_Syntax.InitParser(file.get(), 0); | 3758 m_parser.m_Syntax.InitParser(file.get(), 0); |
3757 FX_BOOL bNumber = FALSE; | 3759 bool bNumber; |
3758 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); | 3760 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(&bNumber); |
3759 if (!bNumber) { | 3761 if (!bNumber) |
3760 return -1; | 3762 return -1; |
3761 } | 3763 |
3762 FX_DWORD objNum = FXSYS_atoi(objnum); | 3764 FX_DWORD objNum = FXSYS_atoi(objnum); |
3763 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL); | 3765 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL); |
3764 if (!pObj) { | 3766 if (!pObj) { |
3765 m_Pos += m_parser.m_Syntax.SavePos(); | 3767 m_Pos += m_parser.m_Syntax.SavePos(); |
3766 return 0; | 3768 return 0; |
3767 } | 3769 } |
3768 CPDF_Dictionary* pDict = pObj->GetDict(); | 3770 CPDF_Dictionary* pDict = pObj->GetDict(); |
3769 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); | 3771 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); |
3770 if (pName) { | 3772 if (pName) { |
3771 if (pName->GetString() == "XRef") { | 3773 if (pName->GetString() == "XRef") { |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4967 if (!m_pLinearizedDict) | 4969 if (!m_pLinearizedDict) |
4968 return -1; | 4970 return -1; |
4969 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4971 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4970 if (!pRange) | 4972 if (!pRange) |
4971 return -1; | 4973 return -1; |
4972 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4974 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4973 if (!pStreamLen) | 4975 if (!pStreamLen) |
4974 return -1; | 4976 return -1; |
4975 return pStreamLen->GetInteger(); | 4977 return pStreamLen->GetInteger(); |
4976 } | 4978 } |
OLD | NEW |