| OLD | NEW |
| 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 "xfa/fde/xml/cfx_saxreader.h" | 7 #include "xfa/fde/xml/cfx_saxreader.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 if (dwLen == static_cast<uint32_t>(-1) || dwStart + dwLen > dwSize) { | 81 if (dwLen == static_cast<uint32_t>(-1) || dwStart + dwLen > dwSize) { |
| 82 dwLen = dwSize - dwStart; | 82 dwLen = dwSize - dwStart; |
| 83 } | 83 } |
| 84 if (dwLen == 0) { | 84 if (dwLen == 0) { |
| 85 return false; | 85 return false; |
| 86 } | 86 } |
| 87 m_dwBufSize = std::min(dwLen, kSaxFileBufSize); | 87 m_dwBufSize = std::min(dwLen, kSaxFileBufSize); |
| 88 m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); | 88 m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); |
| 89 if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) { | 89 if (pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize) != m_dwBufSize && |
| 90 !pFile->IsEOF()) { |
| 90 return false; | 91 return false; |
| 91 } | 92 } |
| 92 m_dwStart = dwStart; | 93 m_dwStart = dwStart; |
| 93 m_dwEnd = dwStart + dwLen; | 94 m_dwEnd = dwStart + dwLen; |
| 94 m_dwCur = dwStart; | 95 m_dwCur = dwStart; |
| 95 m_pFile = pFile; | 96 m_pFile = pFile; |
| 96 m_dwBufIndex = 0; | 97 m_dwBufIndex = 0; |
| 97 return true; | 98 return true; |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool CFX_SAXFile::ReadNextBlock() { | 101 bool CFX_SAXFile::ReadNextBlock() { |
| 101 ASSERT(m_pFile); | 102 ASSERT(m_pFile); |
| 102 uint32_t dwSize = m_dwEnd - m_dwCur; | 103 uint32_t dwSize = m_dwEnd - m_dwCur; |
| 103 if (dwSize == 0) { | 104 if (dwSize == 0) { |
| 104 return false; | 105 return false; |
| 105 } | 106 } |
| 106 m_dwBufSize = std::min(dwSize, kSaxFileBufSize); | 107 m_dwBufSize = std::min(dwSize, kSaxFileBufSize); |
| 107 if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) { | 108 if (m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize) != m_dwBufSize && |
| 109 !m_pFile->IsEOF()) { |
| 108 return false; | 110 return false; |
| 109 } | 111 } |
| 110 m_dwBufIndex = 0; | 112 m_dwBufIndex = 0; |
| 111 return true; | 113 return true; |
| 112 } | 114 } |
| 113 | 115 |
| 114 void CFX_SAXFile::Reset() { | 116 void CFX_SAXFile::Reset() { |
| 115 if (m_pBuf) { | 117 if (m_pBuf) { |
| 116 FX_Free(m_pBuf); | 118 FX_Free(m_pBuf); |
| 117 m_pBuf = nullptr; | 119 m_pBuf = nullptr; |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 CFX_SAXItem* pItem = GetCurrentItem(); | 729 CFX_SAXItem* pItem = GetCurrentItem(); |
| 728 if (!pItem) | 730 if (!pItem) |
| 729 return; | 731 return; |
| 730 | 732 |
| 731 pItem->m_bSkip = true; | 733 pItem->m_bSkip = true; |
| 732 } | 734 } |
| 733 | 735 |
| 734 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { | 736 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { |
| 735 m_pHandler = pHandler; | 737 m_pHandler = pHandler; |
| 736 } | 738 } |
| OLD | NEW |