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

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: fix an undefined variable Created 4 years, 1 month 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 334c14cd45f9d1ed834d80b72bc3595c0de775cd..458153a7def2f2a5c4fa06276e819a486ef68bdf 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -120,18 +120,18 @@ FX_FILESIZE CFPDF_FileStream::GetPosition() {
return m_nCurPos;
}
-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) {
@@ -176,7 +176,7 @@ bool CFPDF_FileStream::Flush() {
#endif // PDF_ENABLE_XFA
CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
- : m_FileAccess(*pFileAccess) {}
+ : m_FileAccess(*pFileAccess), m_nCurPos(0) {}
FX_FILESIZE CPDF_CustomAccess::GetSize() {
return m_FileAccess.m_FileLen;
@@ -186,20 +186,26 @@ void CPDF_CustomAccess::Release() {
delete this;
}
-bool CPDF_CustomAccess::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- if (offset < 0)
- return false;
+bool CPDF_CustomAccess::IsEOF() {
+ return m_nCurPos >= static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen);
+}
- FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
+size_t CPDF_CustomAccess::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ if (offset < 0) {
+ 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,
- reinterpret_cast<uint8_t*>(buffer), size);
+ m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, (uint8_t*)buffer, size);
Tom Sepez 2016/11/16 18:32:01 We probably still need to check the error status o
+ m_nCurPos = newPos.ValueOrDie();
+ return size;
}
// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
@@ -379,21 +385,24 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
class CMemFile final : public IFX_SeekableReadStream {
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; }
+ bool IsEOF() override { return m_nCurPos >= m_size; }
FX_FILESIZE GetSize() override { return m_size; }
- 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);
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:
@@ -401,6 +410,7 @@ class CMemFile final : public IFX_SeekableReadStream {
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