| 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 "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
| 8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 #include "../../../include/fpdfapi/fpdf_page.h" | 9 #include "../../../include/fpdfapi/fpdf_page.h" |
| 10 #include "../../../src/fxcrt/fx_safe_types.h" | 10 #include "../../../src/fxcrt/fx_safe_types.h" |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 CPDF_StreamAcc acc; | 1065 CPDF_StreamAcc acc; |
| 1066 acc.LoadAllData(pStream); | 1066 acc.LoadAllData(pStream); |
| 1067 FX_LPCBYTE pData = acc.GetData(); | 1067 FX_LPCBYTE pData = acc.GetData(); |
| 1068 FX_DWORD dwTotalSize = acc.GetSize(); | 1068 FX_DWORD dwTotalSize = acc.GetSize(); |
| 1069 FX_DWORD segindex = 0; | 1069 FX_DWORD segindex = 0; |
| 1070 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) { | 1070 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) { |
| 1071 FX_INT32 startnum = arrIndex[i].first; | 1071 FX_INT32 startnum = arrIndex[i].first; |
| 1072 if (startnum < 0) { | 1072 if (startnum < 0) { |
| 1073 continue; | 1073 continue; |
| 1074 } | 1074 } |
| 1075 m_dwXrefStartObjNum = base::checked_cast<FX_DWORD, FX_INT32> (startnum); | 1075 m_dwXrefStartObjNum = pdfium::base::checked_cast<FX_DWORD, FX_INT32> (st
artnum); |
| 1076 FX_DWORD count = base::checked_cast<FX_DWORD, FX_INT32> (arrIndex[i].sec
ond); | 1076 FX_DWORD count = pdfium::base::checked_cast<FX_DWORD, FX_INT32> (arrInde
x[i].second); |
| 1077 FX_SAFE_DWORD dwCaculatedSize = segindex; | 1077 FX_SAFE_DWORD dwCaculatedSize = segindex; |
| 1078 dwCaculatedSize += count; | 1078 dwCaculatedSize += count; |
| 1079 dwCaculatedSize *= totalWidth; | 1079 dwCaculatedSize *= totalWidth; |
| 1080 if (!dwCaculatedSize.IsValid() || dwCaculatedSize.ValueOrDie() > dwTotal
Size) { | 1080 if (!dwCaculatedSize.IsValid() || dwCaculatedSize.ValueOrDie() > dwTotal
Size) { |
| 1081 continue; | 1081 continue; |
| 1082 } | 1082 } |
| 1083 FX_LPCBYTE segstart = pData + segindex * totalWidth; | 1083 FX_LPCBYTE segstart = pData + segindex * totalWidth; |
| 1084 FX_SAFE_DWORD dwMaxObjNum = startnum; | 1084 FX_SAFE_DWORD dwMaxObjNum = startnum; |
| 1085 dwMaxObjNum += count; | 1085 dwMaxObjNum += count; |
| 1086 FX_DWORD dwV5Size = base::checked_cast<FX_DWORD, FX_INT32> (m_V5Type.Get
Size()); | 1086 FX_DWORD dwV5Size = pdfium::base::checked_cast<FX_DWORD, FX_INT32> (m_V5
Type.GetSize()); |
| 1087 if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) { | 1087 if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) { |
| 1088 continue; | 1088 continue; |
| 1089 } | 1089 } |
| 1090 for (FX_DWORD j = 0; j < count; j ++) { | 1090 for (FX_DWORD j = 0; j < count; j ++) { |
| 1091 FX_INT32 type = 1; | 1091 FX_INT32 type = 1; |
| 1092 FX_LPCBYTE entrystart = segstart + j * totalWidth; | 1092 FX_LPCBYTE entrystart = segstart + j * totalWidth; |
| 1093 if (WidthArray[0]) { | 1093 if (WidthArray[0]) { |
| 1094 type = _GetVarInt(entrystart, WidthArray[0]); | 1094 type = _GetVarInt(entrystart, WidthArray[0]); |
| 1095 } | 1095 } |
| 1096 if (m_V5Type[startnum + j] == 255) { | 1096 if (m_V5Type[startnum + j] == 255) { |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 } | 2432 } |
| 2433 | 2433 |
| 2434 ToNextLine(); | 2434 ToNextLine(); |
| 2435 FX_FILESIZE StreamStartPos = m_Pos; | 2435 FX_FILESIZE StreamStartPos = m_Pos; |
| 2436 if (pContext) { | 2436 if (pContext) { |
| 2437 pContext->m_DataStart = m_Pos; | 2437 pContext->m_DataStart = m_Pos; |
| 2438 } | 2438 } |
| 2439 | 2439 |
| 2440 CPDF_CryptoHandler* pCryptoHandler = objnum == (FX_DWORD)m_MetadataObjnum ?
NULL : m_pCryptoHandler; | 2440 CPDF_CryptoHandler* pCryptoHandler = objnum == (FX_DWORD)m_MetadataObjnum ?
NULL : m_pCryptoHandler; |
| 2441 if (pCryptoHandler == NULL) { | 2441 if (pCryptoHandler == NULL) { |
| 2442 base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; | 2442 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; |
| 2443 pos += len; | 2443 pos += len; |
| 2444 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { | 2444 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { |
| 2445 m_Pos = pos.ValueOrDie(); | 2445 m_Pos = pos.ValueOrDie(); |
| 2446 } | 2446 } |
| 2447 GetNextWord(); | 2447 GetNextWord(); |
| 2448 if (m_WordSize < 9 || FXSYS_memcmp32(m_WordBuffer, "endstream", 9)) { | 2448 if (m_WordSize < 9 || FXSYS_memcmp32(m_WordBuffer, "endstream", 9)) { |
| 2449 m_Pos = StreamStartPos; | 2449 m_Pos = StreamStartPos; |
| 2450 FX_FILESIZE offset = FindTag(FX_BSTRC("endstream"), 0); | 2450 FX_FILESIZE offset = FindTag(FX_BSTRC("endstream"), 0); |
| 2451 if (offset >= 0) { | 2451 if (offset >= 0) { |
| 2452 FX_FILESIZE curPos = m_Pos; | 2452 FX_FILESIZE curPos = m_Pos; |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3069 new_obj_array.Add(value); | 3069 new_obj_array.Add(value); |
| 3070 } | 3070 } |
| 3071 } | 3071 } |
| 3072 } | 3072 } |
| 3073 break; | 3073 break; |
| 3074 case PDFOBJ_REFERENCE: { | 3074 case PDFOBJ_REFERENCE: { |
| 3075 CPDF_Reference *pRef = (CPDF_Reference*)pObj; | 3075 CPDF_Reference *pRef = (CPDF_Reference*)pObj; |
| 3076 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3076 FX_DWORD dwNum = pRef->GetRefObjNum(); |
| 3077 FX_FILESIZE offset; | 3077 FX_FILESIZE offset; |
| 3078 FX_DWORD original_size = GetObjectSize(dwNum, offset); | 3078 FX_DWORD original_size = GetObjectSize(dwNum, offset); |
| 3079 base::CheckedNumeric<FX_DWORD> size = original_size; | 3079 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; |
| 3080 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m
_dwFileLen) { | 3080 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m
_dwFileLen) { |
| 3081 break; | 3081 break; |
| 3082 } | 3082 } |
| 3083 | 3083 |
| 3084 size += offset; | 3084 size += offset; |
| 3085 size += 512; | 3085 size += 512; |
| 3086 if (!size.IsValid()) { | 3086 if (!size.IsValid()) { |
| 3087 break; | 3087 break; |
| 3088 } | 3088 } |
| 3089 if (size.ValueOrDie() > m_dwFileLen) { | 3089 if (size.ValueOrDie() > m_dwFileLen) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3296 | 3296 |
| 3297 if (m_pDocument == NULL) { | 3297 if (m_pDocument == NULL) { |
| 3298 original_size = (FX_DWORD)m_parser.GetObjectSize(objnum); | 3298 original_size = (FX_DWORD)m_parser.GetObjectSize(objnum); |
| 3299 offset = m_parser.GetObjectOffset(objnum); | 3299 offset = m_parser.GetObjectOffset(objnum); |
| 3300 pParser = &m_parser; | 3300 pParser = &m_parser; |
| 3301 } else { | 3301 } else { |
| 3302 original_size = GetObjectSize(objnum, offset); | 3302 original_size = GetObjectSize(objnum, offset); |
| 3303 pParser = (CPDF_Parser *)(m_pDocument->GetParser()); | 3303 pParser = (CPDF_Parser *)(m_pDocument->GetParser()); |
| 3304 } | 3304 } |
| 3305 | 3305 |
| 3306 base::CheckedNumeric<FX_DWORD> size = original_size; | 3306 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; |
| 3307 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m_dwFileLen) { | 3307 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m_dwFileLen) { |
| 3308 if (pExistInFile) | 3308 if (pExistInFile) |
| 3309 *pExistInFile = FALSE; | 3309 *pExistInFile = FALSE; |
| 3310 | 3310 |
| 3311 return NULL; | 3311 return NULL; |
| 3312 } | 3312 } |
| 3313 | 3313 |
| 3314 size += offset; | 3314 size += offset; |
| 3315 size += 512; | 3315 size += 512; |
| 3316 if (!size.IsValid()) { | 3316 if (!size.IsValid()) { |
| (...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4638 { | 4638 { |
| 4639 FX_INT32 iSize = m_childNode.GetSize(); | 4639 FX_INT32 iSize = m_childNode.GetSize(); |
| 4640 for (FX_INT32 i = 0; i < iSize; ++i) { | 4640 for (FX_INT32 i = 0; i < iSize; ++i) { |
| 4641 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; | 4641 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; |
| 4642 if (pNode) { | 4642 if (pNode) { |
| 4643 delete pNode; | 4643 delete pNode; |
| 4644 } | 4644 } |
| 4645 } | 4645 } |
| 4646 m_childNode.RemoveAll(); | 4646 m_childNode.RemoveAll(); |
| 4647 } | 4647 } |
| OLD | NEW |