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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fgas/crt/fgas_stream.h" 7 #include "xfa/fgas/crt/fgas_stream.h"
8 8
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
10 _FX_OS_ == _FX_WIN64_ 10 _FX_OS_ == _FX_WIN64_
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 void InitStream(); 275 void InitStream();
276 }; 276 };
277 277
278 class CFGAS_FileRead : public IFX_SeekableReadStream { 278 class CFGAS_FileRead : public IFX_SeekableReadStream {
279 public: 279 public:
280 CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream); 280 CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream);
281 ~CFGAS_FileRead() override; 281 ~CFGAS_FileRead() override;
282 282
283 // IFX_SeekableReadStream 283 // IFX_SeekableReadStream
284 void Release() override; 284 void Release() override;
285 bool IsEOF() override;
285 FX_FILESIZE GetSize() override; 286 FX_FILESIZE GetSize() override;
286 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; 287 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
287 288
288 protected: 289 protected:
289 bool m_bReleaseStream; 290 bool m_bReleaseStream;
290 IFX_Stream* m_pStream; 291 IFX_Stream* m_pStream;
292 FX_FILESIZE m_nCurPos;
291 }; 293 };
292 294
293 int32_t FileLength(FXSYS_FILE* file) { 295 int32_t FileLength(FXSYS_FILE* file) {
294 ASSERT(file); 296 ASSERT(file);
295 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ 297 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
296 return _filelength(_fileno(file)); 298 return _filelength(_fileno(file));
297 #else 299 #else
298 int32_t iPos = FXSYS_ftell(file); 300 int32_t iPos = FXSYS_ftell(file);
299 FXSYS_fseek(file, 0, FXSYS_SEEK_END); 301 FXSYS_fseek(file, 0, FXSYS_SEEK_END);
300 int32_t iLen = FXSYS_ftell(file); 302 int32_t iLen = FXSYS_ftell(file);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } 571 }
570 bool CFX_FileReadStreamImp::IsEOF() const { 572 bool CFX_FileReadStreamImp::IsEOF() const {
571 return m_iPosition >= m_iLength; 573 return m_iPosition >= m_iLength;
572 } 574 }
573 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { 575 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {
574 ASSERT(m_pFileRead); 576 ASSERT(m_pFileRead);
575 ASSERT(pBuffer && iBufferSize > 0); 577 ASSERT(pBuffer && iBufferSize > 0);
576 if (iBufferSize > m_iLength - m_iPosition) { 578 if (iBufferSize > m_iLength - m_iPosition) {
577 iBufferSize = m_iLength - m_iPosition; 579 iBufferSize = m_iLength - m_iPosition;
578 } 580 }
579 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { 581 int32_t readSize = pdfium::base::checked_cast<int32_t>(
580 m_iPosition += iBufferSize; 582 m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize));
581 return iBufferSize; 583 if (readSize == iBufferSize || m_pFileRead->IsEOF()) {
584 m_iPosition += readSize;
585 return readSize;
582 } 586 }
583 return 0; 587 return 0;
584 } 588 }
585 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, 589 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr,
586 int32_t iMaxLength, 590 int32_t iMaxLength,
587 bool& bEOS) { 591 bool& bEOS) {
588 ASSERT(m_pFileRead); 592 ASSERT(m_pFileRead);
589 ASSERT(pStr && iMaxLength > 0); 593 ASSERT(pStr && iMaxLength > 0);
590 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; 594 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2;
591 if (iMaxLength <= 0) { 595 if (iMaxLength <= 0) {
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 return pShared; 1456 return pShared;
1453 } 1457 }
1454 1458
1455 IFX_SeekableReadStream* FX_CreateFileRead(IFX_Stream* pBaseStream, 1459 IFX_SeekableReadStream* FX_CreateFileRead(IFX_Stream* pBaseStream,
1456 bool bReleaseStream) { 1460 bool bReleaseStream) {
1457 ASSERT(pBaseStream); 1461 ASSERT(pBaseStream);
1458 return new CFGAS_FileRead(pBaseStream, bReleaseStream); 1462 return new CFGAS_FileRead(pBaseStream, bReleaseStream);
1459 } 1463 }
1460 1464
1461 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream) 1465 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream)
1462 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { 1466 : m_bReleaseStream(bReleaseStream), m_pStream(pStream), m_nCurPos(0) {
1463 ASSERT(m_pStream); 1467 ASSERT(m_pStream);
1464 } 1468 }
1465 CFGAS_FileRead::~CFGAS_FileRead() { 1469 CFGAS_FileRead::~CFGAS_FileRead() {
1466 if (m_bReleaseStream) { 1470 if (m_bReleaseStream) {
1467 m_pStream->Release(); 1471 m_pStream->Release();
1468 } 1472 }
1469 } 1473 }
1474 bool CFGAS_FileRead::IsEOF() {
1475 return m_nCurPos >= (FX_FILESIZE)m_pStream->GetLength();
1476 }
1470 FX_FILESIZE CFGAS_FileRead::GetSize() { 1477 FX_FILESIZE CFGAS_FileRead::GetSize() {
1471 return (FX_FILESIZE)m_pStream->GetLength(); 1478 return (FX_FILESIZE)m_pStream->GetLength();
1472 } 1479 }
1473 1480
1474 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { 1481 size_t CFGAS_FileRead::ReadBlock(void* buffer,
1482 FX_FILESIZE offset,
1483 size_t size) {
1475 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); 1484 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset);
1476 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); 1485 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size);
1477 return iLen == (int32_t)size; 1486 m_nCurPos = offset + pdfium::base::checked_cast<size_t>(iLen);
1487 return pdfium::base::checked_cast<size_t>(iLen);
1478 } 1488 }
1479 1489
1480 void CFGAS_FileRead::Release() { 1490 void CFGAS_FileRead::Release() {
1481 delete this; 1491 delete this;
1482 } 1492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698