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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ++offset; | 54 ++offset; |
55 } | 55 } |
56 return -1; | 56 return -1; |
57 } | 57 } |
58 | 58 |
59 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { | 59 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { |
60 CPDF_Number* pObj = ToNumber(pDict->GetElement(key)); | 60 CPDF_Number* pObj = ToNumber(pDict->GetElement(key)); |
61 return pObj ? pObj->GetInteger() : 0; | 61 return pObj ? pObj->GetInteger() : 0; |
62 } | 62 } |
63 | 63 |
64 bool CheckDirectType(CPDF_Dictionary* pDict, | |
65 const CFX_ByteStringC& key, | |
66 int32_t iType) { | |
67 CPDF_Object* pObj = pDict->GetElement(key); | |
68 return !pObj || pObj->GetType() == iType; | |
69 } | |
70 | |
71 FX_DWORD GetVarInt(const uint8_t* p, int32_t n) { | 64 FX_DWORD GetVarInt(const uint8_t* p, int32_t n) { |
72 FX_DWORD result = 0; | 65 FX_DWORD result = 0; |
73 for (int32_t i = 0; i < n; ++i) | 66 for (int32_t i = 0; i < n; ++i) |
74 result = result * 256 + p[i]; | 67 result = result * 256 + p[i]; |
75 return result; | 68 return result; |
76 } | 69 } |
77 | 70 |
78 int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) { | 71 int32_t GetStreamNCount(CPDF_StreamAcc* pObjStream) { |
79 return pObjStream->GetDict()->GetInteger("N"); | 72 return pObjStream->GetDict()->GetInteger("N"); |
80 } | 73 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; | 122 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; |
130 } | 123 } |
131 | 124 |
132 bool CPDF_Parser::IsValidObjectNumber(FX_DWORD objnum) const { | 125 bool CPDF_Parser::IsValidObjectNumber(FX_DWORD objnum) const { |
133 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; | 126 return !m_ObjectInfo.empty() && objnum <= m_ObjectInfo.rbegin()->first; |
134 } | 127 } |
135 | 128 |
136 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { | 129 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { |
137 m_pEncryptDict = pDict; | 130 m_pEncryptDict = pDict; |
138 } | 131 } |
| 132 |
| 133 FX_FILESIZE CPDF_Parser::GetObjectPositionOrZero(FX_DWORD objnum) const { |
| 134 auto it = m_ObjectInfo.find(objnum); |
| 135 return it != m_ObjectInfo.end() ? it->second.pos : 0; |
| 136 } |
| 137 |
139 void CPDF_Parser::CloseParser(FX_BOOL bReParse) { | 138 void CPDF_Parser::CloseParser(FX_BOOL bReParse) { |
140 m_bVersionUpdated = FALSE; | 139 m_bVersionUpdated = FALSE; |
141 if (!bReParse) { | 140 if (!bReParse) { |
142 delete m_pDocument; | 141 delete m_pDocument; |
143 m_pDocument = NULL; | 142 m_pDocument = NULL; |
144 } | 143 } |
145 if (m_pTrailer) { | 144 if (m_pTrailer) { |
146 m_pTrailer->Release(); | 145 m_pTrailer->Release(); |
147 m_pTrailer = NULL; | 146 m_pTrailer = NULL; |
148 } | 147 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 m_Syntax.SetEncrypt(pCryptoHandler.release()); | 335 m_Syntax.SetEncrypt(pCryptoHandler.release()); |
337 } | 336 } |
338 return PDFPARSE_ERROR_SUCCESS; | 337 return PDFPARSE_ERROR_SUCCESS; |
339 } | 338 } |
340 void CPDF_Parser::ReleaseEncryptHandler() { | 339 void CPDF_Parser::ReleaseEncryptHandler() { |
341 m_Syntax.m_pCryptoHandler.reset(); | 340 m_Syntax.m_pCryptoHandler.reset(); |
342 if (!m_bForceUseSecurityHandler) { | 341 if (!m_bForceUseSecurityHandler) { |
343 m_pSecurityHandler.reset(); | 342 m_pSecurityHandler.reset(); |
344 } | 343 } |
345 } | 344 } |
346 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) { | 345 |
| 346 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) const { |
347 if (!IsValidObjectNumber(objnum)) | 347 if (!IsValidObjectNumber(objnum)) |
348 return 0; | 348 return 0; |
349 | 349 |
350 if (m_V5Type[objnum] == 1) | 350 if (m_V5Type[objnum] == 1) |
351 return m_ObjectInfo[objnum].pos; | 351 return GetObjectPositionOrZero(objnum); |
352 | 352 |
353 if (m_V5Type[objnum] == 2) { | 353 if (m_V5Type[objnum] == 2) { |
354 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 354 FX_FILESIZE pos = GetObjectPositionOrZero(objnum); |
355 return m_ObjectInfo[pos].pos; | 355 return GetObjectPositionOrZero(pos); |
356 } | 356 } |
357 return 0; | 357 return 0; |
358 } | 358 } |
359 | 359 |
360 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { | 360 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) { |
361 if (!LoadCrossRefV4(xrefpos, 0, TRUE)) { | 361 if (!LoadCrossRefV4(xrefpos, 0, TRUE)) { |
362 return FALSE; | 362 return FALSE; |
363 } | 363 } |
364 m_pTrailer = LoadTrailerV4(); | 364 m_pTrailer = LoadTrailerV4(); |
365 if (!m_pTrailer) { | 365 if (!m_pTrailer) { |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 const CPDF_Stream* pStream = | 1231 const CPDF_Stream* pStream = |
1232 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); | 1232 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); |
1233 if (!pStream) | 1233 if (!pStream) |
1234 return nullptr; | 1234 return nullptr; |
1235 | 1235 |
1236 pStreamAcc = new CPDF_StreamAcc; | 1236 pStreamAcc = new CPDF_StreamAcc; |
1237 pStreamAcc->LoadAllData(pStream); | 1237 pStreamAcc->LoadAllData(pStream); |
1238 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); | 1238 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc); |
1239 return pStreamAcc; | 1239 return pStreamAcc; |
1240 } | 1240 } |
1241 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) { | 1241 |
| 1242 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) const { |
1242 if (!IsValidObjectNumber(objnum)) | 1243 if (!IsValidObjectNumber(objnum)) |
1243 return 0; | 1244 return 0; |
1244 | 1245 |
1245 if (m_V5Type[objnum] == 2) { | 1246 if (m_V5Type[objnum] == 2) |
1246 objnum = m_ObjectInfo[objnum].pos; | 1247 objnum = GetObjectPositionOrZero(objnum); |
1247 } | 1248 |
1248 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1249 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
1249 FX_FILESIZE offset = m_ObjectInfo[objnum].pos; | 1250 FX_FILESIZE offset = GetObjectPositionOrZero(objnum); |
1250 if (offset == 0) { | 1251 if (offset == 0) |
1251 return 0; | 1252 return 0; |
1252 } | 1253 |
1253 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), | 1254 FX_FILESIZE* pResult = static_cast<FX_FILESIZE*>(FXSYS_bsearch( |
1254 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 1255 &offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
1255 CompareFileSize); | 1256 sizeof(FX_FILESIZE), CompareFileSize)); |
1256 if (!pResult) { | 1257 if (!pResult) |
1257 return 0; | 1258 return 0; |
1258 } | 1259 |
1259 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == | 1260 if (pResult - m_SortedOffset.GetData() == m_SortedOffset.GetSize() - 1) |
1260 m_SortedOffset.GetSize() - 1) { | |
1261 return 0; | 1261 return 0; |
1262 } | 1262 |
1263 return ((FX_FILESIZE*)pResult)[1] - offset; | 1263 return pResult[1] - offset; |
1264 } | 1264 } |
1265 return 0; | 1265 return 0; |
1266 } | 1266 } |
| 1267 |
1267 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, | 1268 void CPDF_Parser::GetIndirectBinary(FX_DWORD objnum, |
1268 uint8_t*& pBuffer, | 1269 uint8_t*& pBuffer, |
1269 FX_DWORD& size) { | 1270 FX_DWORD& size) { |
1270 pBuffer = NULL; | 1271 pBuffer = NULL; |
1271 size = 0; | 1272 size = 0; |
1272 if (!IsValidObjectNumber(objnum)) | 1273 if (!IsValidObjectNumber(objnum)) |
1273 return; | 1274 return; |
1274 | 1275 |
1275 if (m_V5Type[objnum] == 2) { | 1276 if (m_V5Type[objnum] == 2) { |
1276 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); | 1277 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 | 1693 |
1693 CPDF_SyntaxParser::CPDF_SyntaxParser() { | 1694 CPDF_SyntaxParser::CPDF_SyntaxParser() { |
1694 m_pFileAccess = NULL; | 1695 m_pFileAccess = NULL; |
1695 m_pFileBuf = NULL; | 1696 m_pFileBuf = NULL; |
1696 m_BufSize = CPDF_ModuleMgr::kFileBufSize; | 1697 m_BufSize = CPDF_ModuleMgr::kFileBufSize; |
1697 m_pFileBuf = NULL; | 1698 m_pFileBuf = NULL; |
1698 m_MetadataObjnum = 0; | 1699 m_MetadataObjnum = 0; |
1699 m_dwWordPos = 0; | 1700 m_dwWordPos = 0; |
1700 m_bFileStream = FALSE; | 1701 m_bFileStream = FALSE; |
1701 } | 1702 } |
| 1703 |
1702 CPDF_SyntaxParser::~CPDF_SyntaxParser() { | 1704 CPDF_SyntaxParser::~CPDF_SyntaxParser() { |
1703 FX_Free(m_pFileBuf); | 1705 FX_Free(m_pFileBuf); |
1704 } | 1706 } |
1705 | 1707 |
1706 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch) { | 1708 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch) { |
1707 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); | 1709 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); |
1708 m_Pos = pos; | 1710 m_Pos = pos; |
1709 return GetNextChar(ch); | 1711 return GetNextChar(ch); |
1710 } | 1712 } |
1711 | 1713 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 ch = m_pFileBuf[pos - m_BufOffset]; | 1768 ch = m_pFileBuf[pos - m_BufOffset]; |
1767 return TRUE; | 1769 return TRUE; |
1768 } | 1770 } |
1769 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) { | 1771 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) { |
1770 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { | 1772 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { |
1771 return FALSE; | 1773 return FALSE; |
1772 } | 1774 } |
1773 m_Pos += size; | 1775 m_Pos += size; |
1774 return TRUE; | 1776 return TRUE; |
1775 } | 1777 } |
1776 #define MAX_WORD_BUFFER 256 | 1778 |
1777 void CPDF_SyntaxParser::GetNextWord() { | 1779 void CPDF_SyntaxParser::GetNextWord() { |
1778 m_WordSize = 0; | 1780 m_WordSize = 0; |
1779 m_bIsNumber = TRUE; | 1781 m_bIsNumber = TRUE; |
1780 uint8_t ch; | 1782 uint8_t ch; |
1781 if (!GetNextChar(ch)) { | 1783 if (!GetNextChar(ch)) { |
1782 return; | 1784 return; |
1783 } | 1785 } |
1784 while (1) { | 1786 while (1) { |
1785 while (PDFCharIsWhitespace(ch)) { | 1787 while (PDFCharIsWhitespace(ch)) { |
1786 if (!GetNextChar(ch)) | 1788 if (!GetNextChar(ch)) |
(...skipping 16 matching lines...) Expand all Loading... |
1803 if (ch == '/') { | 1805 if (ch == '/') { |
1804 while (1) { | 1806 while (1) { |
1805 if (!GetNextChar(ch)) | 1807 if (!GetNextChar(ch)) |
1806 return; | 1808 return; |
1807 | 1809 |
1808 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { | 1810 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { |
1809 m_Pos--; | 1811 m_Pos--; |
1810 return; | 1812 return; |
1811 } | 1813 } |
1812 | 1814 |
1813 if (m_WordSize < MAX_WORD_BUFFER) | 1815 if (m_WordSize < sizeof(m_WordBuffer) - 1) |
1814 m_WordBuffer[m_WordSize++] = ch; | 1816 m_WordBuffer[m_WordSize++] = ch; |
1815 } | 1817 } |
1816 } else if (ch == '<') { | 1818 } else if (ch == '<') { |
1817 if (!GetNextChar(ch)) | 1819 if (!GetNextChar(ch)) |
1818 return; | 1820 return; |
1819 if (ch == '<') | 1821 if (ch == '<') |
1820 m_WordBuffer[m_WordSize++] = ch; | 1822 m_WordBuffer[m_WordSize++] = ch; |
1821 else | 1823 else |
1822 m_Pos--; | 1824 m_Pos--; |
1823 } else if (ch == '>') { | 1825 } else if (ch == '>') { |
1824 if (!GetNextChar(ch)) | 1826 if (!GetNextChar(ch)) |
1825 return; | 1827 return; |
1826 if (ch == '>') | 1828 if (ch == '>') |
1827 m_WordBuffer[m_WordSize++] = ch; | 1829 m_WordBuffer[m_WordSize++] = ch; |
1828 else | 1830 else |
1829 m_Pos--; | 1831 m_Pos--; |
1830 } | 1832 } |
1831 return; | 1833 return; |
1832 } | 1834 } |
1833 | 1835 |
1834 while (1) { | 1836 while (1) { |
1835 if (m_WordSize < MAX_WORD_BUFFER) | 1837 if (m_WordSize < sizeof(m_WordBuffer) - 1) |
1836 m_WordBuffer[m_WordSize++] = ch; | 1838 m_WordBuffer[m_WordSize++] = ch; |
1837 | 1839 |
1838 if (!PDFCharIsNumeric(ch)) | 1840 if (!PDFCharIsNumeric(ch)) |
1839 m_bIsNumber = FALSE; | 1841 m_bIsNumber = FALSE; |
1840 if (!GetNextChar(ch)) | 1842 if (!GetNextChar(ch)) |
1841 return; | 1843 return; |
1842 | 1844 |
1843 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { | 1845 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { |
1844 m_Pos--; | 1846 m_Pos--; |
1845 break; | 1847 break; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 if (PDFCharIsLineEnding(ch)) | 2001 if (PDFCharIsLineEnding(ch)) |
2000 break; | 2002 break; |
2001 } | 2003 } |
2002 } | 2004 } |
2003 m_Pos--; | 2005 m_Pos--; |
2004 } | 2006 } |
2005 | 2007 |
2006 CFX_ByteString CPDF_SyntaxParser::GetNextWord(FX_BOOL& bIsNumber) { | 2008 CFX_ByteString CPDF_SyntaxParser::GetNextWord(FX_BOOL& bIsNumber) { |
2007 GetNextWord(); | 2009 GetNextWord(); |
2008 bIsNumber = m_bIsNumber; | 2010 bIsNumber = m_bIsNumber; |
2009 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2011 return CFX_ByteString(m_WordBuffer, m_WordSize); |
2010 } | 2012 } |
2011 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { | 2013 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { |
2012 GetNextWord(); | 2014 FX_BOOL dummy; |
2013 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2015 return GetNextWord(dummy); |
2014 } | 2016 } |
2015 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, | 2017 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, |
2016 FX_DWORD objnum, | 2018 FX_DWORD objnum, |
2017 FX_DWORD gennum, | 2019 FX_DWORD gennum, |
2018 PARSE_CONTEXT* pContext, | 2020 PARSE_CONTEXT* pContext, |
2019 FX_BOOL bDecrypt) { | 2021 FX_BOOL bDecrypt) { |
2020 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2022 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2021 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2023 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2022 return NULL; | 2024 return NULL; |
2023 } | 2025 } |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2481 pFileAccess->ReadBlock( | 2483 pFileAccess->ReadBlock( |
2482 m_pFileBuf, 0, | 2484 m_pFileBuf, 0, |
2483 (size_t)((FX_FILESIZE)m_BufSize > m_FileLen ? m_FileLen : m_BufSize)); | 2485 (size_t)((FX_FILESIZE)m_BufSize > m_FileLen ? m_FileLen : m_BufSize)); |
2484 } | 2486 } |
2485 int32_t CPDF_SyntaxParser::GetDirectNum() { | 2487 int32_t CPDF_SyntaxParser::GetDirectNum() { |
2486 GetNextWord(); | 2488 GetNextWord(); |
2487 if (!m_bIsNumber) { | 2489 if (!m_bIsNumber) { |
2488 return 0; | 2490 return 0; |
2489 } | 2491 } |
2490 m_WordBuffer[m_WordSize] = 0; | 2492 m_WordBuffer[m_WordSize] = 0; |
2491 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); | 2493 return FXSYS_atoi(reinterpret_cast<const FX_CHAR*>(m_WordBuffer)); |
2492 } | 2494 } |
2493 | 2495 |
2494 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, | 2496 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, |
2495 FX_FILESIZE limit, | 2497 FX_FILESIZE limit, |
2496 const CFX_ByteStringC& tag, | 2498 const CFX_ByteStringC& tag, |
2497 FX_BOOL checkKeyword) { | 2499 FX_BOOL checkKeyword) { |
2498 const FX_DWORD taglen = tag.GetLength(); | 2500 const FX_DWORD taglen = tag.GetLength(); |
2499 bool bCheckLeft = !PDFCharIsDelimiter(tag[0]) && !PDFCharIsWhitespace(tag[0]); | 2501 bool bCheckLeft = !PDFCharIsDelimiter(tag[0]) && !PDFCharIsWhitespace(tag[0]); |
2500 bool bCheckRight = !PDFCharIsDelimiter(tag[taglen - 1]) && | 2502 bool bCheckRight = !PDFCharIsDelimiter(tag[taglen - 1]) && |
2501 !PDFCharIsWhitespace(tag[taglen - 1]); | 2503 !PDFCharIsWhitespace(tag[taglen - 1]); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; | 2814 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; |
2813 | 2815 |
2814 FX_FILESIZE m_Pos; | 2816 FX_FILESIZE m_Pos; |
2815 | 2817 |
2816 FX_FILESIZE m_bufferOffset; | 2818 FX_FILESIZE m_bufferOffset; |
2817 | 2819 |
2818 FX_DWORD m_bufferSize; | 2820 FX_DWORD m_bufferSize; |
2819 | 2821 |
2820 CFX_ByteString m_WordBuf; | 2822 CFX_ByteString m_WordBuf; |
2821 | 2823 |
2822 uint8_t m_WordBuffer[257]; | |
2823 | |
2824 FX_DWORD m_WordSize; | |
2825 | |
2826 uint8_t m_bufferData[512]; | 2824 uint8_t m_bufferData[512]; |
2827 | 2825 |
2828 CFX_FileSizeArray m_CrossOffset; | 2826 CFX_FileSizeArray m_CrossOffset; |
2829 | 2827 |
2830 CFX_DWordArray m_XRefStreamList; | 2828 CFX_DWordArray m_XRefStreamList; |
2831 | 2829 |
2832 CFX_DWordArray m_PageObjList; | 2830 CFX_DWordArray m_PageObjList; |
2833 | 2831 |
2834 FX_DWORD m_PagesObjNum; | 2832 FX_DWORD m_PagesObjNum; |
2835 | 2833 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2908 CPDF_DataAvail::CPDF_DataAvail(IFX_FileAvail* pFileAvail, | 2906 CPDF_DataAvail::CPDF_DataAvail(IFX_FileAvail* pFileAvail, |
2909 IFX_FileRead* pFileRead, | 2907 IFX_FileRead* pFileRead, |
2910 FX_BOOL bSupportHintTable) | 2908 FX_BOOL bSupportHintTable) |
2911 : IPDF_DataAvail(pFileAvail, pFileRead) { | 2909 : IPDF_DataAvail(pFileAvail, pFileRead) { |
2912 m_Pos = 0; | 2910 m_Pos = 0; |
2913 m_dwFileLen = 0; | 2911 m_dwFileLen = 0; |
2914 if (m_pFileRead) { | 2912 if (m_pFileRead) { |
2915 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 2913 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); |
2916 } | 2914 } |
2917 m_dwCurrentOffset = 0; | 2915 m_dwCurrentOffset = 0; |
2918 m_WordSize = 0; | |
2919 m_dwXRefOffset = 0; | 2916 m_dwXRefOffset = 0; |
2920 m_bufferOffset = 0; | 2917 m_bufferOffset = 0; |
2921 m_dwFirstPageNo = 0; | 2918 m_dwFirstPageNo = 0; |
2922 m_bufferSize = 0; | 2919 m_bufferSize = 0; |
2923 m_PagesObjNum = 0; | 2920 m_PagesObjNum = 0; |
2924 m_dwCurrentXRefSteam = 0; | 2921 m_dwCurrentXRefSteam = 0; |
2925 m_dwAcroFormObjNum = 0; | 2922 m_dwAcroFormObjNum = 0; |
2926 m_dwInfoObjNum = 0; | 2923 m_dwInfoObjNum = 0; |
2927 m_pDocument = 0; | 2924 m_pDocument = 0; |
2928 m_dwEncryptObjNum = 0; | 2925 m_dwEncryptObjNum = 0; |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3774 } | 3771 } |
3775 pObj->Release(); | 3772 pObj->Release(); |
3776 return -1; | 3773 return -1; |
3777 } | 3774 } |
3778 pHints->AddSegment(m_Pos, req_size); | 3775 pHints->AddSegment(m_Pos, req_size); |
3779 return 0; | 3776 return 0; |
3780 } | 3777 } |
3781 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) { | 3778 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) { |
3782 m_Pos = dwOffset; | 3779 m_Pos = dwOffset; |
3783 } | 3780 } |
3784 #define MAX_WORD_BUFFER 256 | 3781 |
3785 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString& token) { | 3782 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString& token) { |
3786 m_WordSize = 0; | |
3787 uint8_t ch; | 3783 uint8_t ch; |
3788 if (!GetNextChar(ch)) | 3784 if (!GetNextChar(ch)) |
3789 return FALSE; | 3785 return FALSE; |
3790 | 3786 |
3791 while (1) { | 3787 while (1) { |
3792 while (PDFCharIsWhitespace(ch)) { | 3788 while (PDFCharIsWhitespace(ch)) { |
3793 if (!GetNextChar(ch)) | 3789 if (!GetNextChar(ch)) |
3794 return FALSE; | 3790 return FALSE; |
3795 } | 3791 } |
3796 | 3792 |
3797 if (ch != '%') | 3793 if (ch != '%') |
3798 break; | 3794 break; |
3799 | 3795 |
3800 while (1) { | 3796 while (1) { |
3801 if (!GetNextChar(ch)) | 3797 if (!GetNextChar(ch)) |
3802 return FALSE; | 3798 return FALSE; |
3803 if (PDFCharIsLineEnding(ch)) | 3799 if (PDFCharIsLineEnding(ch)) |
3804 break; | 3800 break; |
3805 } | 3801 } |
3806 } | 3802 } |
3807 | 3803 |
| 3804 uint8_t buffer[256]; |
| 3805 FX_DWORD index = 0; |
3808 if (PDFCharIsDelimiter(ch)) { | 3806 if (PDFCharIsDelimiter(ch)) { |
3809 m_WordBuffer[m_WordSize++] = ch; | 3807 buffer[index++] = ch; |
3810 if (ch == '/') { | 3808 if (ch == '/') { |
3811 while (1) { | 3809 while (1) { |
3812 if (!GetNextChar(ch)) | 3810 if (!GetNextChar(ch)) |
3813 return FALSE; | 3811 return FALSE; |
3814 | 3812 |
3815 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { | 3813 if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { |
3816 m_Pos--; | 3814 m_Pos--; |
3817 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3815 CFX_ByteString ret(buffer, index); |
3818 token = ret; | 3816 token = ret; |
3819 return TRUE; | 3817 return TRUE; |
3820 } | 3818 } |
3821 | 3819 |
3822 if (m_WordSize < MAX_WORD_BUFFER) | 3820 if (index < sizeof(buffer)) |
3823 m_WordBuffer[m_WordSize++] = ch; | 3821 buffer[index++] = ch; |
3824 } | 3822 } |
3825 } else if (ch == '<') { | 3823 } else if (ch == '<') { |
3826 if (!GetNextChar(ch)) | 3824 if (!GetNextChar(ch)) |
3827 return FALSE; | 3825 return FALSE; |
3828 | 3826 |
3829 if (ch == '<') | 3827 if (ch == '<') |
3830 m_WordBuffer[m_WordSize++] = ch; | 3828 buffer[index++] = ch; |
3831 else | 3829 else |
3832 m_Pos--; | 3830 m_Pos--; |
3833 } else if (ch == '>') { | 3831 } else if (ch == '>') { |
3834 if (!GetNextChar(ch)) | 3832 if (!GetNextChar(ch)) |
3835 return FALSE; | 3833 return FALSE; |
3836 | 3834 |
3837 if (ch == '>') | 3835 if (ch == '>') |
3838 m_WordBuffer[m_WordSize++] = ch; | 3836 buffer[index++] = ch; |
3839 else | 3837 else |
3840 m_Pos--; | 3838 m_Pos--; |
3841 } | 3839 } |
3842 | 3840 |
3843 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3841 CFX_ByteString ret(buffer, index); |
3844 token = ret; | 3842 token = ret; |
3845 return TRUE; | 3843 return TRUE; |
3846 } | 3844 } |
3847 | 3845 |
3848 while (1) { | 3846 while (1) { |
3849 if (m_WordSize < MAX_WORD_BUFFER) | 3847 if (index < sizeof(buffer)) |
3850 m_WordBuffer[m_WordSize++] = ch; | 3848 buffer[index++] = ch; |
3851 | 3849 |
3852 if (!GetNextChar(ch)) | 3850 if (!GetNextChar(ch)) |
3853 return FALSE; | 3851 return FALSE; |
3854 | 3852 |
3855 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { | 3853 if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { |
3856 m_Pos--; | 3854 m_Pos--; |
3857 break; | 3855 break; |
3858 } | 3856 } |
3859 } | 3857 } |
3860 | 3858 |
3861 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3859 token = CFX_ByteString(buffer, index); |
3862 token = ret; | |
3863 return TRUE; | 3860 return TRUE; |
3864 } | 3861 } |
| 3862 |
3865 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t& ch) { | 3863 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t& ch) { |
3866 FX_FILESIZE pos = m_Pos; | 3864 FX_FILESIZE pos = m_Pos; |
3867 if (pos >= m_dwFileLen) { | 3865 if (pos >= m_dwFileLen) { |
3868 return FALSE; | 3866 return FALSE; |
3869 } | 3867 } |
3870 if (m_bufferOffset >= pos || | 3868 if (m_bufferOffset >= pos || |
3871 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { | 3869 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { |
3872 FX_FILESIZE read_pos = pos; | 3870 FX_FILESIZE read_pos = pos; |
3873 FX_DWORD read_size = 512; | 3871 FX_DWORD read_size = 512; |
3874 if ((FX_FILESIZE)read_size > m_dwFileLen) { | 3872 if ((FX_FILESIZE)read_size > m_dwFileLen) { |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4991 if (!m_pLinearizedDict) | 4989 if (!m_pLinearizedDict) |
4992 return -1; | 4990 return -1; |
4993 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4991 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4994 if (!pRange) | 4992 if (!pRange) |
4995 return -1; | 4993 return -1; |
4996 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4994 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4997 if (!pStreamLen) | 4995 if (!pStreamLen) |
4998 return -1; | 4996 return -1; |
4999 return pStreamLen->GetInteger(); | 4997 return pStreamLen->GetInteger(); |
5000 } | 4998 } |
OLD | NEW |