| 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/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 const uint32_t kMaxNestedArrayLevel = 512; | 36 const uint32_t kMaxNestedArrayLevel = 512; |
| 37 const uint32_t kMaxWordBuffer = 256; | 37 const uint32_t kMaxWordBuffer = 256; |
| 38 const FX_STRSIZE kMaxStringLength = 32767; | 38 const FX_STRSIZE kMaxStringLength = 32767; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize) { | 42 CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize) { |
| 43 m_pBuf = pData; | 43 m_pBuf = pData; |
| 44 m_Size = dwSize; | 44 m_Size = dwSize; |
| 45 m_Pos = 0; | 45 m_Pos = 0; |
| 46 m_pLastObj = NULL; | 46 m_pLastObj = nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 CPDF_StreamParser::~CPDF_StreamParser() { | 49 CPDF_StreamParser::~CPDF_StreamParser() { |
| 50 if (m_pLastObj) { | 50 if (m_pLastObj) { |
| 51 m_pLastObj->Release(); | 51 m_pLastObj->Release(); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder, | 55 uint32_t DecodeAllScanlines(CCodec_ScanlineDecoder* pDecoder, |
| 56 uint8_t*& dest_buf, | 56 uint8_t*& dest_buf, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 uint32_t nComponents = 1; | 161 uint32_t nComponents = 1; |
| 162 CPDF_ColorSpace* pCS = pDoc->LoadColorSpace(pCSObj); | 162 CPDF_ColorSpace* pCS = pDoc->LoadColorSpace(pCSObj); |
| 163 if (!pCS) { | 163 if (!pCS) { |
| 164 nComponents = 3; | 164 nComponents = 3; |
| 165 } else { | 165 } else { |
| 166 nComponents = pCS->CountComponents(); | 166 nComponents = pCS->CountComponents(); |
| 167 pDoc->GetPageData()->ReleaseColorSpace(pCSObj); | 167 pDoc->GetPageData()->ReleaseColorSpace(pCSObj); |
| 168 } | 168 } |
| 169 uint32_t pitch = width; | 169 uint32_t pitch = width; |
| 170 if (bpc && pitch > INT_MAX / bpc) { | 170 if (bpc && pitch > INT_MAX / bpc) { |
| 171 return NULL; | 171 return nullptr; |
| 172 } | 172 } |
| 173 pitch *= bpc; | 173 pitch *= bpc; |
| 174 if (nComponents && pitch > INT_MAX / nComponents) { | 174 if (nComponents && pitch > INT_MAX / nComponents) { |
| 175 return NULL; | 175 return nullptr; |
| 176 } | 176 } |
| 177 pitch *= nComponents; | 177 pitch *= nComponents; |
| 178 if (pitch > INT_MAX - 7) { | 178 if (pitch > INT_MAX - 7) { |
| 179 return NULL; | 179 return nullptr; |
| 180 } | 180 } |
| 181 pitch += 7; | 181 pitch += 7; |
| 182 pitch /= 8; | 182 pitch /= 8; |
| 183 OrigSize = pitch; | 183 OrigSize = pitch; |
| 184 } else { | 184 } else { |
| 185 if (width > INT_MAX - 7) { | 185 if (width > INT_MAX - 7) { |
| 186 return NULL; | 186 return nullptr; |
| 187 } | 187 } |
| 188 OrigSize = ((width + 7) / 8); | 188 OrigSize = ((width + 7) / 8); |
| 189 } | 189 } |
| 190 if (height && OrigSize > INT_MAX / height) { | 190 if (height && OrigSize > INT_MAX / height) { |
| 191 return NULL; | 191 return nullptr; |
| 192 } | 192 } |
| 193 OrigSize *= height; | 193 OrigSize *= height; |
| 194 uint8_t* pData = NULL; | 194 uint8_t* pData = nullptr; |
| 195 uint32_t dwStreamSize; | 195 uint32_t dwStreamSize; |
| 196 if (Decoder.IsEmpty()) { | 196 if (Decoder.IsEmpty()) { |
| 197 if (OrigSize > m_Size - m_Pos) { | 197 if (OrigSize > m_Size - m_Pos) { |
| 198 OrigSize = m_Size - m_Pos; | 198 OrigSize = m_Size - m_Pos; |
| 199 } | 199 } |
| 200 pData = FX_Alloc(uint8_t, OrigSize); | 200 pData = FX_Alloc(uint8_t, OrigSize); |
| 201 FXSYS_memcpy(pData, m_pBuf + m_Pos, OrigSize); | 201 FXSYS_memcpy(pData, m_pBuf + m_Pos, OrigSize); |
| 202 dwStreamSize = OrigSize; | 202 dwStreamSize = OrigSize; |
| 203 m_Pos += OrigSize; | 203 m_Pos += OrigSize; |
| 204 } else { | 204 } else { |
| 205 uint32_t dwDestSize = OrigSize; | 205 uint32_t dwDestSize = OrigSize; |
| 206 dwStreamSize = | 206 dwStreamSize = |
| 207 PDF_DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height, | 207 PDF_DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height, |
| 208 Decoder, pParam, pData, dwDestSize); | 208 Decoder, pParam, pData, dwDestSize); |
| 209 FX_Free(pData); | 209 FX_Free(pData); |
| 210 if ((int)dwStreamSize < 0) | 210 if ((int)dwStreamSize < 0) |
| 211 return NULL; | 211 return nullptr; |
| 212 | 212 |
| 213 uint32_t dwSavePos = m_Pos; | 213 uint32_t dwSavePos = m_Pos; |
| 214 m_Pos += dwStreamSize; | 214 m_Pos += dwStreamSize; |
| 215 while (1) { | 215 while (1) { |
| 216 uint32_t dwPrevPos = m_Pos; | 216 uint32_t dwPrevPos = m_Pos; |
| 217 CPDF_StreamParser::SyntaxType type = ParseNextElement(); | 217 CPDF_StreamParser::SyntaxType type = ParseNextElement(); |
| 218 if (type == CPDF_StreamParser::EndOfData) | 218 if (type == CPDF_StreamParser::EndOfData) |
| 219 break; | 219 break; |
| 220 | 220 |
| 221 if (type != CPDF_StreamParser::Keyword) { | 221 if (type != CPDF_StreamParser::Keyword) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 if (ClipPath.NotNull()) { | 707 if (ClipPath.NotNull()) { |
| 708 m_pParser->GetCurStates()->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, | 708 m_pParser->GetCurStates()->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, |
| 709 TRUE); | 709 TRUE); |
| 710 } | 710 } |
| 711 if (pForm->m_Transparency & PDFTRANS_GROUP) { | 711 if (pForm->m_Transparency & PDFTRANS_GROUP) { |
| 712 CPDF_GeneralStateData* pData = | 712 CPDF_GeneralStateData* pData = |
| 713 m_pParser->GetCurStates()->m_GeneralState.GetModify(); | 713 m_pParser->GetCurStates()->m_GeneralState.GetModify(); |
| 714 pData->m_BlendType = FXDIB_BLEND_NORMAL; | 714 pData->m_BlendType = FXDIB_BLEND_NORMAL; |
| 715 pData->m_StrokeAlpha = 1.0f; | 715 pData->m_StrokeAlpha = 1.0f; |
| 716 pData->m_FillAlpha = 1.0f; | 716 pData->m_FillAlpha = 1.0f; |
| 717 pData->m_pSoftMask = NULL; | 717 pData->m_pSoftMask = nullptr; |
| 718 } | 718 } |
| 719 m_nStreams = 0; | 719 m_nStreams = 0; |
| 720 m_pSingleStream.reset(new CPDF_StreamAcc); | 720 m_pSingleStream.reset(new CPDF_StreamAcc); |
| 721 m_pSingleStream->LoadAllData(pForm->m_pFormStream, FALSE); | 721 m_pSingleStream->LoadAllData(pForm->m_pFormStream, FALSE); |
| 722 m_pData = (uint8_t*)m_pSingleStream->GetData(); | 722 m_pData = (uint8_t*)m_pSingleStream->GetData(); |
| 723 m_Size = m_pSingleStream->GetSize(); | 723 m_Size = m_pSingleStream->GetSize(); |
| 724 m_Status = ToBeContinued; | 724 m_Status = ToBeContinued; |
| 725 m_InternalStage = STAGE_PARSE; | 725 m_InternalStage = STAGE_PARSE; |
| 726 m_CurrentOffset = 0; | 726 m_CurrentOffset = 0; |
| 727 } | 727 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 } | 820 } |
| 821 m_Status = Done; | 821 m_Status = Done; |
| 822 return; | 822 return; |
| 823 } | 823 } |
| 824 steps++; | 824 steps++; |
| 825 if (pPause && pPause->NeedToPauseNow()) { | 825 if (pPause && pPause->NeedToPauseNow()) { |
| 826 break; | 826 break; |
| 827 } | 827 } |
| 828 } | 828 } |
| 829 } | 829 } |
| OLD | NEW |