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/fpdfapi/page/pageint.h" | 7 #include "core/fpdfapi/page/pageint.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 const uint8_t* pData, | 130 const uint8_t* pData, |
131 uint32_t dwSize, | 131 uint32_t dwSize, |
132 const CFX_WeakPtr<CFX_ByteStringPool>& pPool) | 132 const CFX_WeakPtr<CFX_ByteStringPool>& pPool) |
133 : m_pBuf(pData), | 133 : m_pBuf(pData), |
134 m_Size(dwSize), | 134 m_Size(dwSize), |
135 m_Pos(0), | 135 m_Pos(0), |
136 m_pLastObj(nullptr), | 136 m_pLastObj(nullptr), |
137 m_pPool(pPool) {} | 137 m_pPool(pPool) {} |
138 | 138 |
139 CPDF_StreamParser::~CPDF_StreamParser() { | 139 CPDF_StreamParser::~CPDF_StreamParser() { |
140 if (m_pLastObj) { | 140 delete m_pLastObj; |
141 m_pLastObj->Release(); | |
142 } | |
143 } | 141 } |
144 | 142 |
145 CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, | 143 CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, |
146 CPDF_Dictionary* pDict, | 144 CPDF_Dictionary* pDict, |
147 CPDF_Object* pCSObj) { | 145 CPDF_Object* pCSObj) { |
148 if (m_Pos == m_Size) | 146 if (m_Pos == m_Size) |
149 return nullptr; | 147 return nullptr; |
150 | 148 |
151 if (PDFCharIsWhitespace(m_pBuf[m_Pos])) | 149 if (PDFCharIsWhitespace(m_pBuf[m_Pos])) |
152 m_Pos++; | 150 m_Pos++; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 m_Pos = dwSavePos; | 242 m_Pos = dwSavePos; |
245 pData = FX_Alloc(uint8_t, dwStreamSize); | 243 pData = FX_Alloc(uint8_t, dwStreamSize); |
246 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize); | 244 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize); |
247 m_Pos += dwStreamSize; | 245 m_Pos += dwStreamSize; |
248 } | 246 } |
249 pDict->SetIntegerFor("Length", (int)dwStreamSize); | 247 pDict->SetIntegerFor("Length", (int)dwStreamSize); |
250 return new CPDF_Stream(pData, dwStreamSize, pDict); | 248 return new CPDF_Stream(pData, dwStreamSize, pDict); |
251 } | 249 } |
252 | 250 |
253 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { | 251 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { |
254 if (m_pLastObj) { | 252 delete m_pLastObj; |
255 m_pLastObj->Release(); | 253 m_pLastObj = nullptr; |
256 m_pLastObj = nullptr; | |
257 } | |
258 | 254 |
259 m_WordSize = 0; | 255 m_WordSize = 0; |
260 bool bIsNumber = true; | 256 bool bIsNumber = true; |
261 if (!PositionIsInBounds()) | 257 if (!PositionIsInBounds()) |
262 return EndOfData; | 258 return EndOfData; |
263 | 259 |
264 int ch = m_pBuf[m_Pos++]; | 260 int ch = m_pBuf[m_Pos++]; |
265 while (1) { | 261 while (1) { |
266 while (PDFCharIsWhitespace(ch)) { | 262 while (PDFCharIsWhitespace(ch)) { |
267 if (!PositionIsInBounds()) | 263 if (!PositionIsInBounds()) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 if (m_WordSize == 1) | 362 if (m_WordSize == 1) |
367 return new CPDF_String(ReadHexString(), TRUE); | 363 return new CPDF_String(ReadHexString(), TRUE); |
368 | 364 |
369 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pPool); | 365 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pPool); |
370 while (1) { | 366 while (1) { |
371 GetNextWord(bIsNumber); | 367 GetNextWord(bIsNumber); |
372 if (m_WordSize == 2 && m_WordBuffer[0] == '>') | 368 if (m_WordSize == 2 && m_WordBuffer[0] == '>') |
373 break; | 369 break; |
374 | 370 |
375 if (!m_WordSize || m_WordBuffer[0] != '/') { | 371 if (!m_WordSize || m_WordBuffer[0] != '/') { |
376 pDict->Release(); | 372 delete pDict; |
377 return nullptr; | 373 return nullptr; |
378 } | 374 } |
379 | 375 |
380 CFX_ByteString key = | 376 CFX_ByteString key = |
381 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); | 377 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); |
382 CPDF_Object* pObj = ReadNextObject(true, 0); | 378 CPDF_Object* pObj = ReadNextObject(true, 0); |
383 if (!pObj) { | 379 if (!pObj) { |
384 pDict->Release(); | 380 delete pDict; |
385 return nullptr; | 381 return nullptr; |
386 } | 382 } |
387 | 383 |
388 if (key.IsEmpty()) | 384 if (key.IsEmpty()) |
389 pObj->Release(); | 385 delete pObj; |
390 else | 386 else |
391 pDict->SetFor(key, pObj); | 387 pDict->SetFor(key, pObj); |
392 } | 388 } |
393 return pDict; | 389 return pDict; |
394 } | 390 } |
395 | 391 |
396 if (first_char == '[') { | 392 if (first_char == '[') { |
397 if ((!bAllowNestedArray && dwInArrayLevel) || | 393 if ((!bAllowNestedArray && dwInArrayLevel) || |
398 dwInArrayLevel > kMaxNestedArrayLevel) { | 394 dwInArrayLevel > kMaxNestedArrayLevel) { |
399 return nullptr; | 395 return nullptr; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 } | 832 } |
837 m_Status = Done; | 833 m_Status = Done; |
838 return; | 834 return; |
839 } | 835 } |
840 steps++; | 836 steps++; |
841 if (pPause && pPause->NeedToPauseNow()) { | 837 if (pPause && pPause->NeedToPauseNow()) { |
842 break; | 838 break; |
843 } | 839 } |
844 } | 840 } |
845 } | 841 } |
OLD | NEW |