Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 if (m_bufferOffset >= pos || | 1067 if (m_bufferOffset >= pos || |
| 1068 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { | 1068 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { |
| 1069 FX_FILESIZE read_pos = pos; | 1069 FX_FILESIZE read_pos = pos; |
| 1070 uint32_t read_size = 512; | 1070 uint32_t read_size = 512; |
| 1071 if ((FX_FILESIZE)read_size > m_dwFileLen) | 1071 if ((FX_FILESIZE)read_size > m_dwFileLen) |
| 1072 read_size = (uint32_t)m_dwFileLen; | 1072 read_size = (uint32_t)m_dwFileLen; |
| 1073 | 1073 |
| 1074 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) | 1074 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) |
| 1075 read_pos = m_dwFileLen - read_size; | 1075 read_pos = m_dwFileLen - read_size; |
| 1076 | 1076 |
| 1077 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) | 1077 if (m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size) != |
| 1078 read_size && | |
| 1079 !m_pFileRead->IsEOF()) | |
| 1078 return FALSE; | 1080 return FALSE; |
| 1079 | 1081 |
| 1080 m_bufferOffset = read_pos; | 1082 m_bufferOffset = read_pos; |
| 1081 m_bufferSize = read_size; | 1083 m_bufferSize = read_size; |
| 1082 } | 1084 } |
| 1083 ch = m_bufferData[pos - m_bufferOffset]; | 1085 ch = m_bufferData[pos - m_bufferOffset]; |
| 1084 m_Pos++; | 1086 m_Pos++; |
| 1085 return TRUE; | 1087 return TRUE; |
| 1086 } | 1088 } |
| 1087 | 1089 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1180 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1182 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
| 1181 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { | 1183 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { |
| 1182 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); | 1184 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); |
| 1183 CFX_BinaryBuf buf(iSize); | 1185 CFX_BinaryBuf buf(iSize); |
| 1184 uint8_t* pBuf = buf.GetBuffer(); | 1186 uint8_t* pBuf = buf.GetBuffer(); |
| 1185 if (!pBuf) { | 1187 if (!pBuf) { |
| 1186 m_docStatus = PDF_DATAAVAIL_ERROR; | 1188 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1187 return FALSE; | 1189 return FALSE; |
| 1188 } | 1190 } |
| 1189 | 1191 |
| 1190 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) | 1192 if (m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize) != iSize && |
|
Tom Sepez
2016/10/19 23:12:47
this may trigger a signed/unsigned comparision war
| |
| 1193 !m_pFileRead->IsEOF()) | |
| 1191 return FALSE; | 1194 return FALSE; |
| 1192 | 1195 |
| 1193 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 1196 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); |
| 1194 m_syntaxParser.InitParser(file.get(), 0); | 1197 m_syntaxParser.InitParser(file.get(), 0); |
| 1195 | 1198 |
| 1196 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( | 1199 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( |
| 1197 m_syntaxParser.GetObject(nullptr, 0, 0, true)); | 1200 m_syntaxParser.GetObject(nullptr, 0, 0, true)); |
| 1198 if (!pTrailer) { | 1201 if (!pTrailer) { |
| 1199 m_Pos += m_syntaxParser.SavePos(); | 1202 m_Pos += m_syntaxParser.SavePos(); |
| 1200 pHints->AddSegment(m_Pos, iTrailerSize); | 1203 pHints->AddSegment(m_Pos, iTrailerSize); |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1835 return FormAvailable; | 1838 return FormAvailable; |
| 1836 } | 1839 } |
| 1837 | 1840 |
| 1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1841 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
| 1839 | 1842 |
| 1840 CPDF_DataAvail::PageNode::~PageNode() { | 1843 CPDF_DataAvail::PageNode::~PageNode() { |
| 1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1844 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
| 1842 delete m_childNode[i]; | 1845 delete m_childNode[i]; |
| 1843 m_childNode.RemoveAll(); | 1846 m_childNode.RemoveAll(); |
| 1844 } | 1847 } |
| OLD | NEW |