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

Unified Diff: xfa/fgas/crt/fgas_stream.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: xfa/fgas/crt/fgas_stream.cpp
diff --git a/xfa/fgas/crt/fgas_stream.cpp b/xfa/fgas/crt/fgas_stream.cpp
index c3850c00bbe36d7711e113d72c28879aba9d542b..6e3bfa2af94f64543b1593d63c2115a32c4932e5 100644
--- a/xfa/fgas/crt/fgas_stream.cpp
+++ b/xfa/fgas/crt/fgas_stream.cpp
@@ -282,12 +282,14 @@ class CFGAS_FileRead : public IFX_SeekableReadStream {
// IFX_SeekableReadStream
void Release() override;
+ bool IsEOF() override;
FX_FILESIZE GetSize() override;
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+ size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
protected:
bool m_bReleaseStream;
IFX_Stream* m_pStream;
+ FX_FILESIZE m_nCurPos;
};
int32_t FileLength(FXSYS_FILE* file) {
@@ -576,9 +578,11 @@ int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {
if (iBufferSize > m_iLength - m_iPosition) {
iBufferSize = m_iLength - m_iPosition;
}
- if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) {
- m_iPosition += iBufferSize;
- return iBufferSize;
+ int32_t readSize = pdfium::base::checked_cast<int32_t>(
+ m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize));
+ if (readSize == iBufferSize || m_pFileRead->IsEOF()) {
+ m_iPosition += readSize;
+ return readSize;
}
return 0;
}
@@ -1459,7 +1463,7 @@ IFX_SeekableReadStream* FX_CreateFileRead(IFX_Stream* pBaseStream,
}
CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream)
- : m_bReleaseStream(bReleaseStream), m_pStream(pStream) {
+ : m_bReleaseStream(bReleaseStream), m_pStream(pStream), m_nCurPos(0) {
ASSERT(m_pStream);
}
CFGAS_FileRead::~CFGAS_FileRead() {
@@ -1467,14 +1471,20 @@ CFGAS_FileRead::~CFGAS_FileRead() {
m_pStream->Release();
}
}
+bool CFGAS_FileRead::IsEOF() {
+ return m_nCurPos >= (FX_FILESIZE)m_pStream->GetLength();
+}
FX_FILESIZE CFGAS_FileRead::GetSize() {
return (FX_FILESIZE)m_pStream->GetLength();
}
-bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
+size_t CFGAS_FileRead::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset);
int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size);
- return iLen == (int32_t)size;
+ m_nCurPos = offset + pdfium::base::checked_cast<size_t>(iLen);
+ return pdfium::base::checked_cast<size_t>(iLen);
}
void CFGAS_FileRead::Release() {

Powered by Google App Engine
This is Rietveld 408576698