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

Side by Side Diff: fpdfsdk/fpdf_dataavail.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 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 "public/fpdf_dataavail.h" 7 #include "public/fpdf_dataavail.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
14 #include "core/fxcrt/include/fx_safe_types.h"
14 #include "fpdfsdk/include/fsdk_define.h" 15 #include "fpdfsdk/include/fsdk_define.h"
15 #include "public/fpdf_formfill.h" 16 #include "public/fpdf_formfill.h"
17 #include "third_party/base/numerics/safe_conversions_impl.h"
16 18
17 // These checks are here because core/ and public/ cannot depend on each other. 19 // These checks are here because core/ and public/ cannot depend on each other.
18 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, 20 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR,
19 "CPDF_DataAvail::DataError value mismatch"); 21 "CPDF_DataAvail::DataError value mismatch");
20 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, 22 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL,
21 "CPDF_DataAvail::DataNotAvailable value mismatch"); 23 "CPDF_DataAvail::DataNotAvailable value mismatch");
22 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, 24 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL,
23 "CPDF_DataAvail::DataAvailable value mismatch"); 25 "CPDF_DataAvail::DataAvailable value mismatch");
24 26
25 static_assert(CPDF_DataAvail::LinearizationUnknown == PDF_LINEARIZATION_UNKNOWN, 27 static_assert(CPDF_DataAvail::LinearizationUnknown == PDF_LINEARIZATION_UNKNOWN,
(...skipping 25 matching lines...) Expand all
51 FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size) override { 53 FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size) override {
52 return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); 54 return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size);
53 } 55 }
54 56
55 private: 57 private:
56 FX_FILEAVAIL* m_pfileAvail; 58 FX_FILEAVAIL* m_pfileAvail;
57 }; 59 };
58 60
59 class CFPDF_FileAccessWrap : public IFX_FileRead { 61 class CFPDF_FileAccessWrap : public IFX_FileRead {
60 public: 62 public:
61 CFPDF_FileAccessWrap() { m_pFileAccess = nullptr; } 63 CFPDF_FileAccessWrap() {
64 m_pFileAccess = nullptr;
65 m_nCurPos = 0;
66 }
62 ~CFPDF_FileAccessWrap() override {} 67 ~CFPDF_FileAccessWrap() override {}
63 68
64 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } 69 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; }
65 70
71 FX_BOOL IsEOF() override {
72 return m_nCurPos >=
73 pdfium::base::checked_cast<FX_FILESIZE>(m_pFileAccess->m_FileLen);
74 }
75
66 // IFX_FileRead 76 // IFX_FileRead
67 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } 77 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; }
68 78
69 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { 79 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
70 return m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, 80 int blockSize = m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset,
71 (uint8_t*)buffer, size); 81 (uint8_t*)buffer, size);
82 m_nCurPos = offset + pdfium::base::checked_cast<FX_FILESIZE>(blockSize);
83 return pdfium::base::checked_cast<size_t>(blockSize);
72 } 84 }
73 85
74 void Release() override {} 86 void Release() override {}
75 87
76 private: 88 private:
77 FPDF_FILEACCESS* m_pFileAccess; 89 FPDF_FILEACCESS* m_pFileAccess;
90 FX_FILESIZE m_nCurPos;
78 }; 91 };
79 92
80 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { 93 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints {
81 public: 94 public:
82 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { 95 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) {
83 m_pDownloadHints = pDownloadHints; 96 m_pDownloadHints = pDownloadHints;
84 } 97 }
85 ~CFPDF_DownloadHintsWrap() override {} 98 ~CFPDF_DownloadHintsWrap() override {}
86 99
87 public: 100 public:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 CFPDF_DownloadHintsWrap hints_wrap(hints); 192 CFPDF_DownloadHintsWrap hints_wrap(hints);
180 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail( 193 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail(
181 &hints_wrap); 194 &hints_wrap);
182 } 195 }
183 196
184 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { 197 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) {
185 if (!avail) 198 if (!avail)
186 return PDF_LINEARIZATION_UNKNOWN; 199 return PDF_LINEARIZATION_UNKNOWN;
187 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF(); 200 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF();
188 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698