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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/src/fxcrt/extension.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index c705ea73576de248cec87e003635782a35a5ae99..167af85a733ca73fde9ec7a4608f832b3c4264d4 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2854,10 +2854,11 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa
FX_DWORD dwNum = pRef->GetRefObjNum();
FX_FILESIZE offset;
FX_DWORD size = GetObjectSize(pRef->GetRefObjNum(), offset);
- if (!size) {
+
+ 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
break;
- }
- size = (FX_DWORD)((FX_FILESIZE)(offset + size + 512) > m_dwFileLen ? m_dwFileLen - offset : size + 512);
+
+ size = (FX_DWORD)(offset + size + 512 > m_dwFileLen ? m_dwFileLen - offset : size + 512);
palmer 2014/06/12 00:32:04 The expression "offset + size + 512" can overflow,
if (!m_pFileAvail->IsDataAvail(offset, size)) {
pHints->AddSegment(offset, size);
ret_array.Add(pObj);
@@ -3059,8 +3060,13 @@ CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, IFX_DownloadHints* pHint
*pExistInFile = FALSE;
return NULL;
}
+
FX_DWORD size = (FX_DWORD)m_parser.GetObjectSize(objnum);
- size = (FX_DWORD)(((FX_FILESIZE)(offset + size + 512)) > m_dwFileLen ? m_dwFileLen - offset : size + 512);
+
+ if(size <= 0 || offset < 0 || offset > m_dwFileLen)
+ return NULL;
+
+ size = (FX_DWORD)(offset + size + 512 > m_dwFileLen ? m_dwFileLen - offset : size + 512);
if (!m_pFileAvail->IsDataAvail(offset, size)) {
pHints->AddSegment(offset, size);
return NULL;
@@ -3073,7 +3079,11 @@ CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, IFX_DownloadHints* pHint
}
FX_FILESIZE offset;
FX_DWORD size = GetObjectSize(objnum, offset);
- size = (FX_DWORD)((FX_FILESIZE)(offset + size + 512) > m_dwFileLen ? m_dwFileLen - offset : size + 512);
+
+ if(size <= 0 || offset < 0 || offset > m_dwFileLen)
+ return NULL;
+
+ size = (FX_DWORD)(offset + size + 512 > m_dwFileLen ? m_dwFileLen - offset : size + 512);
if (!m_pFileAvail->IsDataAvail(offset, size)) {
pHints->AddSegment(offset, size);
return NULL;
« 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