Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 322333002: Fix the potential integer overflow from "offset + size" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/src/fxcrt/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../fpdf_page/pageint.h" 10 #include "../fpdf_page/pageint.h"
(...skipping 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 new_obj_array.Add(value); 2847 new_obj_array.Add(value);
2848 } 2848 }
2849 } 2849 }
2850 } 2850 }
2851 break; 2851 break;
2852 case PDFOBJ_REFERENCE: { 2852 case PDFOBJ_REFERENCE: {
2853 CPDF_Reference *pRef = (CPDF_Reference*)pObj; 2853 CPDF_Reference *pRef = (CPDF_Reference*)pObj;
2854 FX_DWORD dwNum = pRef->GetRefObjNum(); 2854 FX_DWORD dwNum = pRef->GetRefObjNum();
2855 FX_FILESIZE offset; 2855 FX_FILESIZE offset;
2856 FX_DWORD size = GetObjectSize(pRef->GetRefObjNum(), offset); 2856 FX_DWORD size = GetObjectSize(pRef->GetRefObjNum(), offset);
2857 if (!size) { 2857
2858 if(size <= 0 || offset < 0 || offset > m_dwFileLen)
palmer 2014/06/12 00:32:05 According to ./core/include/fxcrt/fx_system.h:110
jun_fang 2014/07/08 17:43:11 You are right. I will change "<=" to "==" and chan
2858 break; 2859 break;
2859 } 2860
2860 size = (FX_DWORD)((FX_FILESIZE)(offset + size + 512) > m_dwF ileLen ? m_dwFileLen - offset : size + 512); 2861 size = (FX_DWORD)(offset + size + 512 > m_dwFileLen ? m_dwFi leLen - offset : size + 512);
palmer 2014/06/12 00:32:04 The expression "offset + size + 512" can overflow,
2861 if (!m_pFileAvail->IsDataAvail(offset, size)) { 2862 if (!m_pFileAvail->IsDataAvail(offset, size)) {
2862 pHints->AddSegment(offset, size); 2863 pHints->AddSegment(offset, size);
2863 ret_array.Add(pObj); 2864 ret_array.Add(pObj);
2864 count++; 2865 count++;
2865 } else if (!m_objnum_array.Find(dwNum)) { 2866 } else if (!m_objnum_array.Find(dwNum)) {
2866 m_objnum_array.AddObjNum(dwNum); 2867 m_objnum_array.AddObjNum(dwNum);
2867 CPDF_Object *pReferred = m_pDocument->GetIndirectObject( pRef->GetRefObjNum(), NULL); 2868 CPDF_Object *pReferred = m_pDocument->GetIndirectObject( pRef->GetRefObjNum(), NULL);
2868 if (pReferred) { 2869 if (pReferred) {
2869 new_obj_array.Add(pReferred); 2870 new_obj_array.Add(pReferred);
2870 } 2871 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 CPDF_Object *pRet = NULL; 3053 CPDF_Object *pRet = NULL;
3053 if (pExistInFile) { 3054 if (pExistInFile) {
3054 *pExistInFile = TRUE; 3055 *pExistInFile = TRUE;
3055 } 3056 }
3056 if (m_pDocument == NULL) { 3057 if (m_pDocument == NULL) {
3057 FX_FILESIZE offset = m_parser.GetObjectOffset(objnum); 3058 FX_FILESIZE offset = m_parser.GetObjectOffset(objnum);
3058 if (offset < 0) { 3059 if (offset < 0) {
3059 *pExistInFile = FALSE; 3060 *pExistInFile = FALSE;
3060 return NULL; 3061 return NULL;
3061 } 3062 }
3063
3062 FX_DWORD size = (FX_DWORD)m_parser.GetObjectSize(objnum); 3064 FX_DWORD size = (FX_DWORD)m_parser.GetObjectSize(objnum);
3063 size = (FX_DWORD)(((FX_FILESIZE)(offset + size + 512)) > m_dwFileLen ? m _dwFileLen - offset : size + 512); 3065
3066 if(size <= 0 || offset < 0 || offset > m_dwFileLen)
3067 return NULL;
3068
3069 size = (FX_DWORD)(offset + size + 512 > m_dwFileLen ? m_dwFileLen - offs et : size + 512);
3064 if (!m_pFileAvail->IsDataAvail(offset, size)) { 3070 if (!m_pFileAvail->IsDataAvail(offset, size)) {
3065 pHints->AddSegment(offset, size); 3071 pHints->AddSegment(offset, size);
3066 return NULL; 3072 return NULL;
3067 } 3073 }
3068 pRet = m_parser.ParseIndirectObject(NULL, objnum); 3074 pRet = m_parser.ParseIndirectObject(NULL, objnum);
3069 if (!pRet && pExistInFile) { 3075 if (!pRet && pExistInFile) {
3070 *pExistInFile = FALSE; 3076 *pExistInFile = FALSE;
3071 } 3077 }
3072 return pRet; 3078 return pRet;
3073 } 3079 }
3074 FX_FILESIZE offset; 3080 FX_FILESIZE offset;
3075 FX_DWORD size = GetObjectSize(objnum, offset); 3081 FX_DWORD size = GetObjectSize(objnum, offset);
3076 size = (FX_DWORD)((FX_FILESIZE)(offset + size + 512) > m_dwFileLen ? m_dwFil eLen - offset : size + 512); 3082
3083 if(size <= 0 || offset < 0 || offset > m_dwFileLen)
3084 return NULL;
3085
3086 size = (FX_DWORD)(offset + size + 512 > m_dwFileLen ? m_dwFileLen - offset : size + 512);
3077 if (!m_pFileAvail->IsDataAvail(offset, size)) { 3087 if (!m_pFileAvail->IsDataAvail(offset, size)) {
3078 pHints->AddSegment(offset, size); 3088 pHints->AddSegment(offset, size);
3079 return NULL; 3089 return NULL;
3080 } 3090 }
3081 CPDF_Parser *pParser = (CPDF_Parser *)(m_pDocument->GetParser()); 3091 CPDF_Parser *pParser = (CPDF_Parser *)(m_pDocument->GetParser());
3082 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); 3092 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL);
3083 if (!pRet && pExistInFile) { 3093 if (!pRet && pExistInFile) {
3084 *pExistInFile = FALSE; 3094 *pExistInFile = FALSE;
3085 } 3095 }
3086 return pRet; 3096 return pRet;
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
4369 { 4379 {
4370 FX_INT32 iSize = m_childNode.GetSize(); 4380 FX_INT32 iSize = m_childNode.GetSize();
4371 for (FX_INT32 i = 0; i < iSize; ++i) { 4381 for (FX_INT32 i = 0; i < iSize; ++i) {
4372 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; 4382 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i];
4373 if (pNode) { 4383 if (pNode) {
4374 delete pNode; 4384 delete pNode;
4375 } 4385 }
4376 } 4386 }
4377 m_childNode.RemoveAll(); 4387 m_childNode.RemoveAll();
4378 } 4388 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fxcrt/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698