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

Side by Side Diff: core/fxcrt/fx_extension.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 <utility> 7 #include <utility>
8 8
9 #include "core/fxcrt/extension.h" 9 #include "core/fxcrt/extension.h"
10 #include "core/fxcrt/include/fx_basic.h" 10 #include "core/fxcrt/include/fx_basic.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return; 96 return;
97 } 97 }
98 delete this; 98 delete this;
99 } 99 }
100 100
101 FX_FILESIZE CFX_MemoryStream::GetSize() { 101 FX_FILESIZE CFX_MemoryStream::GetSize() {
102 return (FX_FILESIZE)m_nCurSize; 102 return (FX_FILESIZE)m_nCurSize;
103 } 103 }
104 104
105 FX_BOOL CFX_MemoryStream::IsEOF() { 105 FX_BOOL CFX_MemoryStream::IsEOF() {
106 return m_nCurPos >= (size_t)GetSize(); 106 return m_nCurPos >= pdfium::base::checked_cast<size_t>(GetSize());
107 } 107 }
108 108
109 FX_FILESIZE CFX_MemoryStream::GetPosition() { 109 FX_FILESIZE CFX_MemoryStream::GetPosition() {
110 return (FX_FILESIZE)m_nCurPos; 110 return (FX_FILESIZE)m_nCurPos;
111 } 111 }
112 112
113 FX_BOOL CFX_MemoryStream::ReadBlock(void* buffer, 113 size_t CFX_MemoryStream::ReadBlock(void* buffer,
114 FX_FILESIZE offset, 114 FX_FILESIZE offset,
115 size_t size) { 115 size_t size) {
116 if (!buffer || !size) { 116 if (!buffer || !size) {
117 return FALSE; 117 return 0;
118 } 118 }
119 119
120 FX_SAFE_SIZE_T newPos = size; 120 FX_SAFE_SIZE_T newPos = size;
121 newPos += offset; 121 newPos += offset;
122 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || 122 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 ||
123 newPos.ValueOrDie() > m_nCurSize) { 123 newPos.ValueOrDie() > m_nCurSize) {
124 return FALSE; 124 return 0;
125 } 125 }
126 126
127 m_nCurPos = newPos.ValueOrDie(); 127 m_nCurPos = newPos.ValueOrDie();
128 if (m_dwFlags & FX_MEMSTREAM_Consecutive) { 128 if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
129 FXSYS_memcpy(buffer, m_Blocks[0] + (size_t)offset, size); 129 FXSYS_memcpy(buffer, m_Blocks[0] + (size_t)offset, size);
130 return TRUE; 130 return size;
131 } 131 }
132 size_t readSize = size;
132 size_t nStartBlock = (size_t)offset / m_nGrowSize; 133 size_t nStartBlock = (size_t)offset / m_nGrowSize;
133 offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); 134 offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize);
134 while (size) { 135 while (size) {
135 size_t nRead = m_nGrowSize - (size_t)offset; 136 size_t nRead = m_nGrowSize - (size_t)offset;
136 if (nRead > size) { 137 if (nRead > size) {
137 nRead = size; 138 nRead = size;
138 } 139 }
139 FXSYS_memcpy(buffer, m_Blocks[(int)nStartBlock] + (size_t)offset, nRead); 140 FXSYS_memcpy(buffer, m_Blocks[(int)nStartBlock] + (size_t)offset, nRead);
140 buffer = ((uint8_t*)buffer) + nRead; 141 buffer = ((uint8_t*)buffer) + nRead;
141 size -= nRead; 142 size -= nRead;
142 nStartBlock++; 143 nStartBlock++;
143 offset = 0; 144 offset = 0;
144 } 145 }
145 return TRUE; 146 return readSize;
146 } 147 }
147 148
148 size_t CFX_MemoryStream::ReadBlock(void* buffer, size_t size) { 149 size_t CFX_MemoryStream::ReadBlock(void* buffer, size_t size) {
149 if (m_nCurPos >= m_nCurSize) { 150 if (m_nCurPos >= m_nCurSize) {
150 return 0; 151 return 0;
151 } 152 }
152 size_t nRead = std::min(size, m_nCurSize - m_nCurPos); 153 size_t nRead = std::min(size, m_nCurSize - m_nCurPos);
153 if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) { 154 if (ReadBlock(buffer, (int32_t)m_nCurPos, nRead) != nRead && !IsEOF()) {
154 return 0; 155 return 0;
155 } 156 }
156 return nRead; 157 return nRead;
157 } 158 }
158 159
159 FX_BOOL CFX_MemoryStream::WriteBlock(const void* buffer, 160 FX_BOOL CFX_MemoryStream::WriteBlock(const void* buffer,
160 FX_FILESIZE offset, 161 FX_FILESIZE offset,
161 size_t size) { 162 size_t size) {
162 if (!buffer || !size) { 163 if (!buffer || !size) {
163 return FALSE; 164 return FALSE;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 299 }
299 300
300 FX_BOOL CFX_CRTFileStream::IsEOF() { 301 FX_BOOL CFX_CRTFileStream::IsEOF() {
301 return GetPosition() >= GetSize(); 302 return GetPosition() >= GetSize();
302 } 303 }
303 304
304 FX_FILESIZE CFX_CRTFileStream::GetPosition() { 305 FX_FILESIZE CFX_CRTFileStream::GetPosition() {
305 return m_pFile->GetPosition(); 306 return m_pFile->GetPosition();
306 } 307 }
307 308
308 FX_BOOL CFX_CRTFileStream::ReadBlock(void* buffer, 309 size_t CFX_CRTFileStream::ReadBlock(void* buffer,
309 FX_FILESIZE offset, 310 FX_FILESIZE offset,
310 size_t size) { 311 size_t size) {
311 return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset); 312 return m_pFile->ReadPos(buffer, size, offset);
312 } 313 }
313 314
314 size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) { 315 size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) {
315 return m_pFile->Read(buffer, size); 316 return m_pFile->Read(buffer, size);
316 } 317 }
317 318
318 FX_BOOL CFX_CRTFileStream::WriteBlock(const void* buffer, 319 FX_BOOL CFX_CRTFileStream::WriteBlock(const void* buffer,
319 FX_FILESIZE offset, 320 FX_FILESIZE offset,
320 size_t size) { 321 size_t size) {
321 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); 322 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 b = ((const uint8_t*)pGUID)[i]; 610 b = ((const uint8_t*)pGUID)[i];
610 *pBuf++ = gs_FX_pHexChars[b >> 4]; 611 *pBuf++ = gs_FX_pHexChars[b >> 4];
611 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; 612 *pBuf++ = gs_FX_pHexChars[b & 0x0F];
612 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { 613 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
613 *pBuf++ = L'-'; 614 *pBuf++ = L'-';
614 } 615 }
615 } 616 }
616 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); 617 bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
617 } 618 }
618 #endif // PDF_ENABLE_XFA 619 #endif // PDF_ENABLE_XFA
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698