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/parser/cpdf_data_avail.h" | 7 #include "core/fpdfapi/parser/cpdf_data_avail.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
950 if (m_bufferOffset >= pos || | 950 if (m_bufferOffset >= pos || |
951 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { | 951 (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { |
952 FX_FILESIZE read_pos = pos; | 952 FX_FILESIZE read_pos = pos; |
953 uint32_t read_size = 512; | 953 uint32_t read_size = 512; |
954 if ((FX_FILESIZE)read_size > m_dwFileLen) | 954 if ((FX_FILESIZE)read_size > m_dwFileLen) |
955 read_size = (uint32_t)m_dwFileLen; | 955 read_size = (uint32_t)m_dwFileLen; |
956 | 956 |
957 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) | 957 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) |
958 read_pos = m_dwFileLen - read_size; | 958 read_pos = m_dwFileLen - read_size; |
959 | 959 |
960 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) | 960 if (m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size) != |
961 read_size && | |
962 !m_pFileRead->IsEOF()) | |
961 return false; | 963 return false; |
962 | 964 |
963 m_bufferOffset = read_pos; | 965 m_bufferOffset = read_pos; |
964 m_bufferSize = read_size; | 966 m_bufferSize = read_size; |
965 } | 967 } |
966 ch = m_bufferData[pos - m_bufferOffset]; | 968 ch = m_bufferData[pos - m_bufferOffset]; |
967 m_Pos++; | 969 m_Pos++; |
968 return true; | 970 return true; |
969 } | 971 } |
970 | 972 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1055 } else { | 1057 } else { |
1056 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; | 1058 m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; |
1057 } | 1059 } |
1058 return true; | 1060 return true; |
1059 } | 1061 } |
1060 | 1062 |
1061 bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { | 1063 bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { |
1062 int32_t iTrailerSize = | 1064 int32_t iTrailerSize = |
1063 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); | 1065 (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); |
1064 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { | 1066 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { |
1065 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); | 1067 uint32_t iSize = pdfium::base::checked_cast<uint32_t>(m_Pos + iTrailerSize - |
1068 m_dwTrailerOffset); | |
1066 CFX_BinaryBuf buf(iSize); | 1069 CFX_BinaryBuf buf(iSize); |
1067 uint8_t* pBuf = buf.GetBuffer(); | 1070 uint8_t* pBuf = buf.GetBuffer(); |
1068 if (!pBuf) { | 1071 if (!pBuf) { |
1069 m_docStatus = PDF_DATAAVAIL_ERROR; | 1072 m_docStatus = PDF_DATAAVAIL_ERROR; |
1070 return false; | 1073 return false; |
1071 } | 1074 } |
1072 | 1075 |
1073 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) | 1076 if (m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize) != iSize && |
1077 !m_pFileRead->IsEOF()) | |
1074 return false; | 1078 return false; |
1075 | 1079 |
1076 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false)); | 1080 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false)); |
Tom Sepez
2016/11/14 20:27:40
same issue here with reads < isize.
| |
1077 m_syntaxParser.InitParser(file.get(), 0); | 1081 m_syntaxParser.InitParser(file.get(), 0); |
1078 | 1082 |
1079 std::unique_ptr<CPDF_Object> pTrailer( | 1083 std::unique_ptr<CPDF_Object> pTrailer( |
1080 m_syntaxParser.GetObject(nullptr, 0, 0, true)); | 1084 m_syntaxParser.GetObject(nullptr, 0, 0, true)); |
1081 if (!pTrailer) { | 1085 if (!pTrailer) { |
1082 m_Pos += m_syntaxParser.SavePos(); | 1086 m_Pos += m_syntaxParser.SavePos(); |
1083 pHints->AddSegment(m_Pos, iTrailerSize); | 1087 pHints->AddSegment(m_Pos, iTrailerSize); |
1084 return false; | 1088 return false; |
1085 } | 1089 } |
1086 | 1090 |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1688 return FormAvailable; | 1692 return FormAvailable; |
1689 } | 1693 } |
1690 | 1694 |
1691 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1695 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
1692 | 1696 |
1693 CPDF_DataAvail::PageNode::~PageNode() { | 1697 CPDF_DataAvail::PageNode::~PageNode() { |
1694 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1698 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
1695 delete m_childNode[i]; | 1699 delete m_childNode[i]; |
1696 m_childNode.RemoveAll(); | 1700 m_childNode.RemoveAll(); |
1697 } | 1701 } |
OLD | NEW |