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

Unified Diff: fpdfsdk/fpdfview.cpp

Issue 2430743003: in the attempt to fix 627393, changed IFX_FileRead's readBlock to return the length it reads
Patch Set: remove .tmp files Created 4 years, 2 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
Index: fpdfsdk/fpdfview.cpp
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 3c60ab0041cf07db61fb4051b992955c70ffd14a..ed502872a01f412a5a442c29d8b602ac87fb435e 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -118,18 +118,18 @@ FX_FILESIZE CFPDF_FileStream::GetPosition() {
return m_nCurPos;
}
-FX_BOOL CFPDF_FileStream::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
+size_t CFPDF_FileStream::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
if (!buffer || !size || !m_pFS->ReadBlock)
- return FALSE;
+ return 0;
if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
(FPDF_DWORD)size) == 0) {
m_nCurPos = offset + size;
- return TRUE;
+ return size;
}
- return FALSE;
+ return 0;
}
size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) {
@@ -175,6 +175,7 @@ FX_BOOL CFPDF_FileStream::Flush() {
CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) {
m_FileAccess = *pFileAccess;
+ m_nCurPos = 0;
#ifdef PDF_ENABLE_XFA
m_BufferOffset = (uint32_t)-1;
#endif // PDF_ENABLE_XFA
@@ -220,21 +221,26 @@ void CPDF_CustomAccess::Release() {
delete this;
}
-FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
+FX_BOOL CPDF_CustomAccess::IsEOF() {
+ return m_nCurPos >= static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen);
+}
+
+size_t CPDF_CustomAccess::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
if (offset < 0) {
- return FALSE;
+ return 0;
}
FX_SAFE_FILESIZE newPos =
pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
newPos += offset;
if (!newPos.IsValid() ||
newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
- return FALSE;
+ return 0;
}
- return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer,
- size);
+ m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, size);
+ m_nCurPos = newPos.ValueOrDie();
+ return size;
}
// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
@@ -417,22 +423,25 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
class CMemFile final : public IFX_FileRead {
public:
- CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {}
+ CMemFile(uint8_t* pBuf, FX_FILESIZE size)
+ : m_pBuf(pBuf), m_size(size), m_nCurPos(0) {}
void Release() override { delete this; }
+ FX_BOOL IsEOF() override { return m_nCurPos >= m_size; }
FX_FILESIZE GetSize() override { return m_size; }
- FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
+ size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
if (offset < 0) {
- return FALSE;
+ return 0;
}
FX_SAFE_FILESIZE newPos =
pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
newPos += offset;
if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) {
- return FALSE;
+ return 0;
}
FXSYS_memcpy(buffer, m_pBuf + offset, size);
- return TRUE;
+ m_nCurPos = offset + size;
+ return size;
}
private:
@@ -440,6 +449,7 @@ class CMemFile final : public IFX_FileRead {
uint8_t* const m_pBuf;
const FX_FILESIZE m_size;
+ FX_FILESIZE m_nCurPos;
};
DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,

Powered by Google App Engine
This is Rietveld 408576698