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

Side by Side 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 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/fpdfview.h" 7 #include "public/fpdfview.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 bool CFPDF_FileStream::IsEOF() { 115 bool CFPDF_FileStream::IsEOF() {
116 return m_nCurPos >= GetSize(); 116 return m_nCurPos >= GetSize();
117 } 117 }
118 118
119 FX_FILESIZE CFPDF_FileStream::GetPosition() { 119 FX_FILESIZE CFPDF_FileStream::GetPosition() {
120 return m_nCurPos; 120 return m_nCurPos;
121 } 121 }
122 122
123 bool CFPDF_FileStream::ReadBlock(void* buffer, 123 size_t CFPDF_FileStream::ReadBlock(void* buffer,
124 FX_FILESIZE offset, 124 FX_FILESIZE offset,
125 size_t size) { 125 size_t size) {
126 if (!buffer || !size || !m_pFS->ReadBlock) 126 if (!buffer || !size || !m_pFS->ReadBlock)
127 return false; 127 return 0;
128 128
129 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, 129 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
130 (FPDF_DWORD)size) == 0) { 130 (FPDF_DWORD)size) == 0) {
131 m_nCurPos = offset + size; 131 m_nCurPos = offset + size;
132 return true; 132 return size;
133 } 133 }
134 return false; 134 return 0;
135 } 135 }
136 136
137 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) { 137 size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size) {
138 if (!buffer || !size || !m_pFS->ReadBlock) 138 if (!buffer || !size || !m_pFS->ReadBlock)
139 return 0; 139 return 0;
140 140
141 FX_FILESIZE nSize = GetSize(); 141 FX_FILESIZE nSize = GetSize();
142 if (m_nCurPos >= nSize) 142 if (m_nCurPos >= nSize)
143 return 0; 143 return 0;
144 FX_FILESIZE dwAvail = nSize - m_nCurPos; 144 FX_FILESIZE dwAvail = nSize - m_nCurPos;
(...skipping 24 matching lines...) Expand all
169 169
170 bool CFPDF_FileStream::Flush() { 170 bool CFPDF_FileStream::Flush() {
171 if (!m_pFS || !m_pFS->Flush) 171 if (!m_pFS || !m_pFS->Flush)
172 return true; 172 return true;
173 173
174 return m_pFS->Flush(m_pFS->clientData) == 0; 174 return m_pFS->Flush(m_pFS->clientData) == 0;
175 } 175 }
176 #endif // PDF_ENABLE_XFA 176 #endif // PDF_ENABLE_XFA
177 177
178 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) 178 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
179 : m_FileAccess(*pFileAccess) {} 179 : m_FileAccess(*pFileAccess), m_nCurPos(0) {}
180 180
181 FX_FILESIZE CPDF_CustomAccess::GetSize() { 181 FX_FILESIZE CPDF_CustomAccess::GetSize() {
182 return m_FileAccess.m_FileLen; 182 return m_FileAccess.m_FileLen;
183 } 183 }
184 184
185 void CPDF_CustomAccess::Release() { 185 void CPDF_CustomAccess::Release() {
186 delete this; 186 delete this;
187 } 187 }
188 188
189 bool CPDF_CustomAccess::ReadBlock(void* buffer, 189 bool CPDF_CustomAccess::IsEOF() {
190 FX_FILESIZE offset, 190 return m_nCurPos >= static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen);
191 size_t size) { 191 }
192 if (offset < 0)
193 return false;
194 192
195 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); 193 size_t CPDF_CustomAccess::ReadBlock(void* buffer,
194 FX_FILESIZE offset,
195 size_t size) {
196 if (offset < 0) {
197 return 0;
198 }
199 FX_SAFE_FILESIZE newPos =
200 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size);
196 newPos += offset; 201 newPos += offset;
197 if (!newPos.IsValid() || 202 if (!newPos.IsValid() ||
198 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { 203 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
199 return false; 204 return 0;
200 } 205 }
201 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, 206 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
202 reinterpret_cast<uint8_t*>(buffer), size); 207 m_nCurPos = newPos.ValueOrDie();
208 return size;
203 } 209 }
204 210
205 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS 211 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
206 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; 212 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF;
207 213
208 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { 214 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) {
209 switch (policy) { 215 switch (policy) {
210 case FPDF_POLICY_MACHINETIME_ACCESS: { 216 case FPDF_POLICY_MACHINETIME_ACCESS: {
211 if (enable) 217 if (enable)
212 foxit_sandbox_policy |= 0x01; 218 foxit_sandbox_policy |= 0x01;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return true; 378 return true;
373 } 379 }
374 380
375 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { 381 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) {
376 return document && (static_cast<CPDFXFA_Context*>(document))->LoadXFADoc(); 382 return document && (static_cast<CPDFXFA_Context*>(document))->LoadXFADoc();
377 } 383 }
378 #endif // PDF_ENABLE_XFA 384 #endif // PDF_ENABLE_XFA
379 385
380 class CMemFile final : public IFX_SeekableReadStream { 386 class CMemFile final : public IFX_SeekableReadStream {
381 public: 387 public:
382 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} 388 CMemFile(uint8_t* pBuf, FX_FILESIZE size)
389 : m_pBuf(pBuf), m_size(size), m_nCurPos(0) {}
383 390
384 void Release() override { delete this; } 391 void Release() override { delete this; }
392 bool IsEOF() override { return m_nCurPos >= m_size; }
385 FX_FILESIZE GetSize() override { return m_size; } 393 FX_FILESIZE GetSize() override { return m_size; }
386 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { 394 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
387 if (offset < 0) { 395 if (offset < 0) {
388 return false; 396 return 0;
389 } 397 }
390 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); 398 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
391 newPos += offset; 399 newPos += offset;
392 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) { 400 if (!newPos.IsValid() || newPos.ValueOrDie() > m_size) {
393 return false; 401 return 0;
394 } 402 }
395 FXSYS_memcpy(buffer, m_pBuf + offset, size); 403 FXSYS_memcpy(buffer, m_pBuf + offset, size);
396 return true; 404 m_nCurPos = offset + size;
405 return size;
397 } 406 }
398 407
399 private: 408 private:
400 ~CMemFile() override {} 409 ~CMemFile() override {}
401 410
402 uint8_t* const m_pBuf; 411 uint8_t* const m_pBuf;
403 const FX_FILESIZE m_size; 412 const FX_FILESIZE m_size;
413 FX_FILESIZE m_nCurPos;
404 }; 414 };
405 415
406 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, 416 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
407 int size, 417 int size,
408 FPDF_BYTESTRING password) { 418 FPDF_BYTESTRING password) {
409 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); 419 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size);
410 std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); 420 std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser);
411 pParser->SetPassword(password); 421 pParser->SetPassword(password);
412 422
413 std::unique_ptr<CPDF_Document> pDocument( 423 std::unique_ptr<CPDF_Document> pDocument(
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 if (!buffer) { 1118 if (!buffer) {
1109 *buflen = len; 1119 *buflen = len;
1110 } else if (*buflen >= len) { 1120 } else if (*buflen >= len) {
1111 memcpy(buffer, utf16Name.c_str(), len); 1121 memcpy(buffer, utf16Name.c_str(), len);
1112 *buflen = len; 1122 *buflen = len;
1113 } else { 1123 } else {
1114 *buflen = -1; 1124 *buflen = -1;
1115 } 1125 }
1116 return (FPDF_DEST)pDestObj; 1126 return (FPDF_DEST)pDestObj;
1117 } 1127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698