| 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 "pageint.h" | 7 #include "pageint.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 m_pLastObj = NULL; | 242 m_pLastObj = NULL; |
| 243 } | 243 } |
| 244 CPDF_StreamParser::~CPDF_StreamParser() { | 244 CPDF_StreamParser::~CPDF_StreamParser() { |
| 245 if (m_pLastObj) { | 245 if (m_pLastObj) { |
| 246 m_pLastObj->Release(); | 246 m_pLastObj->Release(); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, | 249 FX_DWORD _DecodeAllScanlines(ICodec_ScanlineDecoder* pDecoder, |
| 250 uint8_t*& dest_buf, | 250 uint8_t*& dest_buf, |
| 251 FX_DWORD& dest_size) { | 251 FX_DWORD& dest_size) { |
| 252 if (pDecoder == NULL) { | 252 if (!pDecoder) { |
| 253 return (FX_DWORD)-1; | 253 return (FX_DWORD)-1; |
| 254 } | 254 } |
| 255 int ncomps = pDecoder->CountComps(); | 255 int ncomps = pDecoder->CountComps(); |
| 256 int bpc = pDecoder->GetBPC(); | 256 int bpc = pDecoder->GetBPC(); |
| 257 int width = pDecoder->GetWidth(); | 257 int width = pDecoder->GetWidth(); |
| 258 int height = pDecoder->GetHeight(); | 258 int height = pDecoder->GetHeight(); |
| 259 int pitch = (width * ncomps * bpc + 7) / 8; | 259 int pitch = (width * ncomps * bpc + 7) / 8; |
| 260 if (height == 0 || pitch > (1 << 30) / height) { | 260 if (height == 0 || pitch > (1 << 30) / height) { |
| 261 delete pDecoder; | 261 delete pDecoder; |
| 262 return -1; | 262 return -1; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 pParam = pDict->GetDict("DecodeParms"); | 346 pParam = pDict->GetDict("DecodeParms"); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 FX_DWORD width = pDict->GetInteger("Width"); | 349 FX_DWORD width = pDict->GetInteger("Width"); |
| 350 FX_DWORD height = pDict->GetInteger("Height"); | 350 FX_DWORD height = pDict->GetInteger("Height"); |
| 351 FX_DWORD OrigSize = 0; | 351 FX_DWORD OrigSize = 0; |
| 352 if (pCSObj) { | 352 if (pCSObj) { |
| 353 FX_DWORD bpc = pDict->GetInteger("BitsPerComponent"); | 353 FX_DWORD bpc = pDict->GetInteger("BitsPerComponent"); |
| 354 FX_DWORD nComponents = 1; | 354 FX_DWORD nComponents = 1; |
| 355 CPDF_ColorSpace* pCS = pDoc->LoadColorSpace(pCSObj); | 355 CPDF_ColorSpace* pCS = pDoc->LoadColorSpace(pCSObj); |
| 356 if (pCS == NULL) { | 356 if (!pCS) { |
| 357 nComponents = 3; | 357 nComponents = 3; |
| 358 } else { | 358 } else { |
| 359 nComponents = pCS->CountComponents(); | 359 nComponents = pCS->CountComponents(); |
| 360 pDoc->GetPageData()->ReleaseColorSpace(pCSObj); | 360 pDoc->GetPageData()->ReleaseColorSpace(pCSObj); |
| 361 } | 361 } |
| 362 FX_DWORD pitch = width; | 362 FX_DWORD pitch = width; |
| 363 if (bpc && pitch > INT_MAX / bpc) { | 363 if (bpc && pitch > INT_MAX / bpc) { |
| 364 return NULL; | 364 return NULL; |
| 365 } | 365 } |
| 366 pitch *= bpc; | 366 pitch *= bpc; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 if (m_WordSize == 2 && m_WordBuffer[0] == '>') { | 627 if (m_WordSize == 2 && m_WordBuffer[0] == '>') { |
| 628 break; | 628 break; |
| 629 } | 629 } |
| 630 if (m_WordBuffer[0] != '/') { | 630 if (m_WordBuffer[0] != '/') { |
| 631 pDict->Release(); | 631 pDict->Release(); |
| 632 return NULL; | 632 return NULL; |
| 633 } | 633 } |
| 634 CFX_ByteString key = | 634 CFX_ByteString key = |
| 635 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); | 635 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); |
| 636 CPDF_Object* pObj = ReadNextObject(TRUE); | 636 CPDF_Object* pObj = ReadNextObject(TRUE); |
| 637 if (pObj == NULL) { | 637 if (!pObj) { |
| 638 if (pDict) { | 638 if (pDict) { |
| 639 pDict->Release(); | 639 pDict->Release(); |
| 640 } | 640 } |
| 641 return NULL; | 641 return NULL; |
| 642 } | 642 } |
| 643 if (!key.IsEmpty()) { | 643 if (!key.IsEmpty()) { |
| 644 pDict->SetAt(key, pObj); | 644 pDict->SetAt(key, pObj); |
| 645 } else { | 645 } else { |
| 646 pObj->Release(); | 646 pObj->Release(); |
| 647 } | 647 } |
| 648 } | 648 } |
| 649 return pDict; | 649 return pDict; |
| 650 } | 650 } |
| 651 if (first_char == '[') { | 651 if (first_char == '[') { |
| 652 if (!bAllowNestedArray && bInArray) { | 652 if (!bAllowNestedArray && bInArray) { |
| 653 return NULL; | 653 return NULL; |
| 654 } | 654 } |
| 655 CPDF_Array* pArray = CPDF_Array::Create(); | 655 CPDF_Array* pArray = CPDF_Array::Create(); |
| 656 while (1) { | 656 while (1) { |
| 657 CPDF_Object* pObj = ReadNextObject(bAllowNestedArray, TRUE); | 657 CPDF_Object* pObj = ReadNextObject(bAllowNestedArray, TRUE); |
| 658 if (pObj == NULL) { | 658 if (!pObj) { |
| 659 if (m_WordSize == 0 || m_WordBuffer[0] == ']') { | 659 if (m_WordSize == 0 || m_WordBuffer[0] == ']') { |
| 660 return pArray; | 660 return pArray; |
| 661 } | 661 } |
| 662 if (m_WordBuffer[0] == '[') { | 662 if (m_WordBuffer[0] == '[') { |
| 663 continue; | 663 continue; |
| 664 } | 664 } |
| 665 } else { | 665 } else { |
| 666 pArray->Add(pObj); | 666 pArray->Add(pObj); |
| 667 } | 667 } |
| 668 } | 668 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 } | 917 } |
| 918 if (!m_pSingleStream) | 918 if (!m_pSingleStream) |
| 919 FX_Free(m_pData); | 919 FX_Free(m_pData); |
| 920 m_pParser = NULL; | 920 m_pParser = NULL; |
| 921 m_pStreamArray = NULL; | 921 m_pStreamArray = NULL; |
| 922 m_pSingleStream = NULL; | 922 m_pSingleStream = NULL; |
| 923 m_pData = NULL; | 923 m_pData = NULL; |
| 924 m_Status = Ready; | 924 m_Status = Ready; |
| 925 } | 925 } |
| 926 void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) { | 926 void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) { |
| 927 if (m_Status != Ready || pPage == NULL || pPage->m_pDocument == NULL || | 927 if (m_Status != Ready || !pPage || !pPage->m_pDocument || |
| 928 pPage->m_pFormDict == NULL) { | 928 !pPage->m_pFormDict) { |
| 929 m_Status = Done; | 929 m_Status = Done; |
| 930 return; | 930 return; |
| 931 } | 931 } |
| 932 m_pObjects = pPage; | 932 m_pObjects = pPage; |
| 933 m_bForm = FALSE; | 933 m_bForm = FALSE; |
| 934 if (pOptions) { | 934 if (pOptions) { |
| 935 m_Options = *pOptions; | 935 m_Options = *pOptions; |
| 936 } | 936 } |
| 937 m_Status = ToBeContinued; | 937 m_Status = ToBeContinued; |
| 938 m_InternalStage = PAGEPARSE_STAGE_GETCONTENT; | 938 m_InternalStage = PAGEPARSE_STAGE_GETCONTENT; |
| 939 m_CurrentOffset = 0; | 939 m_CurrentOffset = 0; |
| 940 CPDF_Object* pContent = pPage->m_pFormDict->GetElementValue("Contents"); | 940 CPDF_Object* pContent = pPage->m_pFormDict->GetElementValue("Contents"); |
| 941 if (pContent == NULL) { | 941 if (!pContent) { |
| 942 m_Status = Done; | 942 m_Status = Done; |
| 943 return; | 943 return; |
| 944 } | 944 } |
| 945 if (CPDF_Stream* pStream = pContent->AsStream()) { | 945 if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 946 m_nStreams = 0; | 946 m_nStreams = 0; |
| 947 m_pSingleStream = new CPDF_StreamAcc; | 947 m_pSingleStream = new CPDF_StreamAcc; |
| 948 m_pSingleStream->LoadAllData(pStream, FALSE); | 948 m_pSingleStream->LoadAllData(pStream, FALSE); |
| 949 } else if (CPDF_Array* pArray = pContent->AsArray()) { | 949 } else if (CPDF_Array* pArray = pContent->AsArray()) { |
| 950 m_nStreams = pArray->GetCount(); | 950 m_nStreams = pArray->GetCount(); |
| 951 if (m_nStreams == 0) { | 951 if (m_nStreams == 0) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 } | 1120 } |
| 1121 m_Status = Done; | 1121 m_Status = Done; |
| 1122 return; | 1122 return; |
| 1123 } | 1123 } |
| 1124 steps++; | 1124 steps++; |
| 1125 if (pPause && pPause->NeedToPauseNow()) { | 1125 if (pPause && pPause->NeedToPauseNow()) { |
| 1126 break; | 1126 break; |
| 1127 } | 1127 } |
| 1128 } | 1128 } |
| 1129 } | 1129 } |
| OLD | NEW |