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

Unified Diff: fpdfsdk/src/fpdfview.cpp

Issue 440563003: Fix buffer size boundary check offset by 1 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: More correction Created 6 years, 5 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/fpdfview.cpp
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 63d4fbdcdeb94828fedb959c9d9a2e0f284f1ccd..af24e71b941c4fef170cc81d39a449821d07ae73 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -35,27 +35,25 @@ FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch)
FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size)
{
- FX_SAFE_DWORD newPos = size;
- newPos += pos;
- if (!newPos.IsValid() || newPos.ValueOrDie() >= m_FileAccess.m_FileLen) {
- return FALSE;
- }
-
- return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
+ FX_SAFE_DWORD newPos = size;
+ newPos += pos;
+ if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) {
+ return FALSE;
+ }
+ return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
}
FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
{
- if (offset < 0) {
- return FALSE;
- }
- FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size);
- newPos += offset;
- if (!newPos.IsValid() || newPos.ValueOrDie() >= m_FileAccess.m_FileLen) {
- return FALSE;
- }
-
- return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(FX_LPBYTE) buffer, size);
+ if (offset < 0) {
+ return FALSE;
+ }
+ FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size);
+ newPos += offset;
+ if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) {
+ return FALSE;
+ }
+ return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(FX_LPBYTE) buffer, size);
}
//0 bit: FPDF_POLICY_MACHINETIME_ACCESS
@@ -301,15 +299,13 @@ public:
virtual FX_FILESIZE GetSize() {return m_size;}
virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
{
- if (offset < 0) {
- return FALSE;
- }
-
- FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size);
- newPos += offset;
- if (!newPos.IsValid() || newPos.ValueOrDie() >= (FX_DWORD)m_size) return FALSE;
+ if (offset < 0) {
+ return FALSE;
+ }
+ FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size);
+ newPos += offset;
+ if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) return FALSE;
FXSYS_memcpy(buffer, m_pBuf+offset, size);
-
return TRUE;
}
private:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698