| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  153       pParam = pDict->GetDictBy("DecodeParms"); |  153       pParam = pDict->GetDictBy("DecodeParms"); | 
|  154     } |  154     } | 
|  155   } |  155   } | 
|  156   uint32_t width = pDict->GetIntegerBy("Width"); |  156   uint32_t width = pDict->GetIntegerBy("Width"); | 
|  157   uint32_t height = pDict->GetIntegerBy("Height"); |  157   uint32_t height = pDict->GetIntegerBy("Height"); | 
|  158   uint32_t OrigSize = 0; |  158   uint32_t OrigSize = 0; | 
|  159   if (pCSObj) { |  159   if (pCSObj) { | 
|  160     uint32_t bpc = pDict->GetIntegerBy("BitsPerComponent"); |  160     uint32_t bpc = pDict->GetIntegerBy("BitsPerComponent"); | 
|  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; |  | 
|  165     } else { |  | 
|  166       nComponents = pCS->CountComponents(); |  164       nComponents = pCS->CountComponents(); | 
|  167       pDoc->GetPageData()->ReleaseColorSpace(pCSObj); |  165       pDoc->GetPageData()->ReleaseColorSpace(pCSObj); | 
 |  166     } else { | 
 |  167       nComponents = 3; | 
|  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 nullptr; |  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 nullptr; |  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 nullptr; |  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 nullptr; |  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 nullptr; |  191     return nullptr; | 
|  192   } |  192  | 
|  193   OrigSize *= height; |  193   OrigSize *= height; | 
|  194   uint8_t* pData = nullptr; |  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; | 
| (...skipping 617 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 |