| 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 "core/include/fpdfapi/fpdf_parser.h" | 7 #include "core/include/fpdfapi/fpdf_parser.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; | 1192 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; |
| 1193 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1193 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1194 m_Syntax.RestorePos(pos); | 1194 m_Syntax.RestorePos(pos); |
| 1195 const char kFormStream[] = "/Form\0stream"; | 1195 const char kFormStream[] = "/Form\0stream"; |
| 1196 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); | 1196 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); |
| 1197 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; | 1197 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; |
| 1198 m_Syntax.RestorePos(SavedPos); | 1198 m_Syntax.RestorePos(SavedPos); |
| 1199 return TRUE; | 1199 return TRUE; |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, | 1202 CPDF_Object* CPDF_Parser::ParseIndirectObject( |
| 1203 FX_DWORD objnum, | 1203 CPDF_IndirectObjectHolder* pObjList, |
| 1204 PARSE_CONTEXT* pContext) { | 1204 FX_DWORD objnum, |
| 1205 PARSE_CONTEXT* pContext) { |
| 1205 if (!IsValidObjectNumber(objnum)) | 1206 if (!IsValidObjectNumber(objnum)) |
| 1206 return nullptr; | 1207 return nullptr; |
| 1207 | 1208 |
| 1208 // Prevent circular parsing the same object. | 1209 // Prevent circular parsing the same object. |
| 1209 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) | 1210 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) |
| 1210 return nullptr; | 1211 return nullptr; |
| 1211 ScopedSetInsertion<FX_DWORD> local_insert(&m_ParsingObjNums, objnum); | 1212 ScopedSetInsertion<FX_DWORD> local_insert(&m_ParsingObjNums, objnum); |
| 1212 | 1213 |
| 1213 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1214 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
| 1214 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1215 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 } | 1391 } |
| 1391 nextoff = m_Syntax.SavePos(); | 1392 nextoff = m_Syntax.SavePos(); |
| 1392 } | 1393 } |
| 1393 size = (FX_DWORD)(nextoff - pos); | 1394 size = (FX_DWORD)(nextoff - pos); |
| 1394 pBuffer = FX_Alloc(uint8_t, size); | 1395 pBuffer = FX_Alloc(uint8_t, size); |
| 1395 m_Syntax.RestorePos(pos); | 1396 m_Syntax.RestorePos(pos); |
| 1396 m_Syntax.ReadBlock(pBuffer, size); | 1397 m_Syntax.ReadBlock(pBuffer, size); |
| 1397 m_Syntax.RestorePos(SavedPos); | 1398 m_Syntax.RestorePos(SavedPos); |
| 1398 } | 1399 } |
| 1399 | 1400 |
| 1400 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, | 1401 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt( |
| 1401 FX_FILESIZE pos, | 1402 CPDF_IndirectObjectHolder* pObjList, |
| 1402 FX_DWORD objnum, | 1403 FX_FILESIZE pos, |
| 1403 PARSE_CONTEXT* pContext) { | 1404 FX_DWORD objnum, |
| 1405 PARSE_CONTEXT* pContext) { |
| 1404 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1406 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1405 m_Syntax.RestorePos(pos); | 1407 m_Syntax.RestorePos(pos); |
| 1406 bool bIsNumber; | 1408 bool bIsNumber; |
| 1407 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); | 1409 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 1408 if (!bIsNumber) { | 1410 if (!bIsNumber) { |
| 1409 m_Syntax.RestorePos(SavedPos); | 1411 m_Syntax.RestorePos(SavedPos); |
| 1410 return NULL; | 1412 return NULL; |
| 1411 } | 1413 } |
| 1412 FX_FILESIZE objOffset = m_Syntax.SavePos(); | 1414 FX_FILESIZE objOffset = m_Syntax.SavePos(); |
| 1413 objOffset -= word.GetLength(); | 1415 objOffset -= word.GetLength(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1435 } | 1437 } |
| 1436 m_Syntax.RestorePos(SavedPos); | 1438 m_Syntax.RestorePos(SavedPos); |
| 1437 if (pObj) { | 1439 if (pObj) { |
| 1438 if (!objnum) | 1440 if (!objnum) |
| 1439 pObj->m_ObjNum = parser_objnum; | 1441 pObj->m_ObjNum = parser_objnum; |
| 1440 pObj->m_GenNum = parser_gennum; | 1442 pObj->m_GenNum = parser_gennum; |
| 1441 } | 1443 } |
| 1442 return pObj; | 1444 return pObj; |
| 1443 } | 1445 } |
| 1444 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 1446 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( |
| 1445 CPDF_IndirectObjects* pObjList, | 1447 CPDF_IndirectObjectHolder* pObjList, |
| 1446 FX_FILESIZE pos, | 1448 FX_FILESIZE pos, |
| 1447 FX_DWORD objnum, | 1449 FX_DWORD objnum, |
| 1448 PARSE_CONTEXT* pContext, | 1450 PARSE_CONTEXT* pContext, |
| 1449 FX_FILESIZE* pResultPos) { | 1451 FX_FILESIZE* pResultPos) { |
| 1450 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1452 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
| 1451 m_Syntax.RestorePos(pos); | 1453 m_Syntax.RestorePos(pos); |
| 1452 bool bIsNumber; | 1454 bool bIsNumber; |
| 1453 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); | 1455 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
| 1454 if (!bIsNumber) { | 1456 if (!bIsNumber) { |
| 1455 m_Syntax.RestorePos(SavedPos); | 1457 m_Syntax.RestorePos(SavedPos); |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 | 2036 |
| 2035 CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool* bIsNumber) { | 2037 CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool* bIsNumber) { |
| 2036 GetNextWordInternal(bIsNumber); | 2038 GetNextWordInternal(bIsNumber); |
| 2037 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2039 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
| 2038 } | 2040 } |
| 2039 | 2041 |
| 2040 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { | 2042 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { |
| 2041 return GetNextWord(nullptr); | 2043 return GetNextWord(nullptr); |
| 2042 } | 2044 } |
| 2043 | 2045 |
| 2044 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, | 2046 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, |
| 2045 FX_DWORD objnum, | 2047 FX_DWORD objnum, |
| 2046 FX_DWORD gennum, | 2048 FX_DWORD gennum, |
| 2047 PARSE_CONTEXT* pContext, | 2049 PARSE_CONTEXT* pContext, |
| 2048 FX_BOOL bDecrypt) { | 2050 FX_BOOL bDecrypt) { |
| 2049 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2051 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
| 2050 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2052 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
| 2051 return NULL; | 2053 return NULL; |
| 2052 } | 2054 } |
| 2053 FX_FILESIZE SavedPos = m_Pos; | 2055 FX_FILESIZE SavedPos = m_Pos; |
| 2054 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2056 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2190 m_Pos = SavedPos; | 2192 m_Pos = SavedPos; |
| 2191 return nullptr; | 2193 return nullptr; |
| 2192 } | 2194 } |
| 2193 if (bTypeOnly) | 2195 if (bTypeOnly) |
| 2194 return (CPDF_Object*)PDFOBJ_INVALID; | 2196 return (CPDF_Object*)PDFOBJ_INVALID; |
| 2195 | 2197 |
| 2196 return nullptr; | 2198 return nullptr; |
| 2197 } | 2199 } |
| 2198 | 2200 |
| 2199 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( | 2201 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( |
| 2200 CPDF_IndirectObjects* pObjList, | 2202 CPDF_IndirectObjectHolder* pObjList, |
| 2201 FX_DWORD objnum, | 2203 FX_DWORD objnum, |
| 2202 FX_DWORD gennum, | 2204 FX_DWORD gennum, |
| 2203 PARSE_CONTEXT* pContext) { | 2205 PARSE_CONTEXT* pContext) { |
| 2204 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2206 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
| 2205 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2207 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
| 2206 return NULL; | 2208 return NULL; |
| 2207 } | 2209 } |
| 2208 FX_FILESIZE SavedPos = m_Pos; | 2210 FX_FILESIZE SavedPos = m_Pos; |
| 2209 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2211 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
| 2210 bool bIsNumber; | 2212 bool bIsNumber; |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2754 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pHints); | 2756 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pHints); |
| 2755 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHints); | 2757 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHints); |
| 2756 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints* pHints); | 2758 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints* pHints); |
| 2757 | 2759 |
| 2758 int32_t CheckCrossRefStream(IFX_DownloadHints* pHints, | 2760 int32_t CheckCrossRefStream(IFX_DownloadHints* pHints, |
| 2759 FX_FILESIZE& xref_offset); | 2761 FX_FILESIZE& xref_offset); |
| 2760 FX_BOOL IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen); | 2762 FX_BOOL IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen); |
| 2761 void SetStartOffset(FX_FILESIZE dwOffset); | 2763 void SetStartOffset(FX_FILESIZE dwOffset); |
| 2762 FX_BOOL GetNextToken(CFX_ByteString& token); | 2764 FX_BOOL GetNextToken(CFX_ByteString& token); |
| 2763 FX_BOOL GetNextChar(uint8_t& ch); | 2765 FX_BOOL GetNextChar(uint8_t& ch); |
| 2764 CPDF_Object* ParseIndirectObjectAt(FX_FILESIZE pos, | 2766 CPDF_Object* ParseIndirectObjectAt( |
| 2765 FX_DWORD objnum, | 2767 FX_FILESIZE pos, |
| 2766 CPDF_IndirectObjects* pObjList = NULL); | 2768 FX_DWORD objnum, |
| 2769 CPDF_IndirectObjectHolder* pObjList = NULL); |
| 2767 CPDF_Object* GetObject(FX_DWORD objnum, | 2770 CPDF_Object* GetObject(FX_DWORD objnum, |
| 2768 IFX_DownloadHints* pHints, | 2771 IFX_DownloadHints* pHints, |
| 2769 FX_BOOL* pExistInFile); | 2772 FX_BOOL* pExistInFile); |
| 2770 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); | 2773 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); |
| 2771 FX_BOOL PreparePageItem(); | 2774 FX_BOOL PreparePageItem(); |
| 2772 FX_BOOL LoadPages(IFX_DownloadHints* pHints); | 2775 FX_BOOL LoadPages(IFX_DownloadHints* pHints); |
| 2773 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); | 2776 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); |
| 2774 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); | 2777 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); |
| 2775 int32_t CheckLinearizedData(IFX_DownloadHints* pHints); | 2778 int32_t CheckLinearizedData(IFX_DownloadHints* pHints); |
| 2776 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadHints* pHints); | 2779 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadHints* pHints); |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3626 CPDF_Stream* pStream = ToStream(pHintStream.get()); | 3629 CPDF_Stream* pStream = ToStream(pHintStream.get()); |
| 3627 if (pStream && pHintTables->LoadHintStream(pStream)) | 3630 if (pStream && pHintTables->LoadHintStream(pStream)) |
| 3628 m_pHintTables = std::move(pHintTables); | 3631 m_pHintTables = std::move(pHintTables); |
| 3629 | 3632 |
| 3630 m_docStatus = PDF_DATAAVAIL_DONE; | 3633 m_docStatus = PDF_DATAAVAIL_DONE; |
| 3631 return TRUE; | 3634 return TRUE; |
| 3632 } | 3635 } |
| 3633 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( | 3636 CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt( |
| 3634 FX_FILESIZE pos, | 3637 FX_FILESIZE pos, |
| 3635 FX_DWORD objnum, | 3638 FX_DWORD objnum, |
| 3636 CPDF_IndirectObjects* pObjList) { | 3639 CPDF_IndirectObjectHolder* pObjList) { |
| 3637 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 3640 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
| 3638 m_syntaxParser.RestorePos(pos); | 3641 m_syntaxParser.RestorePos(pos); |
| 3639 bool bIsNumber; | 3642 bool bIsNumber; |
| 3640 CFX_ByteString word = m_syntaxParser.GetNextWord(&bIsNumber); | 3643 CFX_ByteString word = m_syntaxParser.GetNextWord(&bIsNumber); |
| 3641 if (!bIsNumber) | 3644 if (!bIsNumber) |
| 3642 return nullptr; | 3645 return nullptr; |
| 3643 | 3646 |
| 3644 FX_DWORD parser_objnum = FXSYS_atoi(word); | 3647 FX_DWORD parser_objnum = FXSYS_atoi(word); |
| 3645 if (objnum && parser_objnum != objnum) | 3648 if (objnum && parser_objnum != objnum) |
| 3646 return nullptr; | 3649 return nullptr; |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4982 if (!m_pLinearizedDict) | 4985 if (!m_pLinearizedDict) |
| 4983 return -1; | 4986 return -1; |
| 4984 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4987 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
| 4985 if (!pRange) | 4988 if (!pRange) |
| 4986 return -1; | 4989 return -1; |
| 4987 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4990 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
| 4988 if (!pStreamLen) | 4991 if (!pStreamLen) |
| 4989 return -1; | 4992 return -1; |
| 4990 return pStreamLen->GetInteger(); | 4993 return pStreamLen->GetInteger(); |
| 4991 } | 4994 } |
| OLD | NEW |