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