| 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 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return FALSE; | 77 return FALSE; |
| 78 } | 78 } |
| 79 if (dwLen == static_cast<uint32_t>(-1) || dwStart + dwLen > dwSize) { | 79 if (dwLen == static_cast<uint32_t>(-1) || dwStart + dwLen > dwSize) { |
| 80 dwLen = dwSize - dwStart; | 80 dwLen = dwSize - dwStart; |
| 81 } | 81 } |
| 82 if (dwLen == 0) { | 82 if (dwLen == 0) { |
| 83 return FALSE; | 83 return FALSE; |
| 84 } | 84 } |
| 85 m_dwBufSize = std::min(dwLen, kSaxFileBufSize); | 85 m_dwBufSize = std::min(dwLen, kSaxFileBufSize); |
| 86 m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); | 86 m_pBuf = FX_Alloc(uint8_t, m_dwBufSize); |
| 87 if (!pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize)) { | 87 if (pFile->ReadBlock(m_pBuf, dwStart, m_dwBufSize) != m_dwBufSize && |
| 88 !pFile->IsEOF()) { |
| 88 return FALSE; | 89 return FALSE; |
| 89 } | 90 } |
| 90 m_dwStart = dwStart; | 91 m_dwStart = dwStart; |
| 91 m_dwEnd = dwStart + dwLen; | 92 m_dwEnd = dwStart + dwLen; |
| 92 m_dwCur = dwStart; | 93 m_dwCur = dwStart; |
| 93 m_pFile = pFile; | 94 m_pFile = pFile; |
| 94 m_dwBufIndex = 0; | 95 m_dwBufIndex = 0; |
| 95 return TRUE; | 96 return TRUE; |
| 96 } | 97 } |
| 97 FX_BOOL CFX_SAXFile::ReadNextBlock() { | 98 FX_BOOL CFX_SAXFile::ReadNextBlock() { |
| 98 ASSERT(m_pFile); | 99 ASSERT(m_pFile); |
| 99 uint32_t dwSize = m_dwEnd - m_dwCur; | 100 uint32_t dwSize = m_dwEnd - m_dwCur; |
| 100 if (dwSize == 0) { | 101 if (dwSize == 0) { |
| 101 return FALSE; | 102 return FALSE; |
| 102 } | 103 } |
| 103 m_dwBufSize = std::min(dwSize, kSaxFileBufSize); | 104 m_dwBufSize = std::min(dwSize, kSaxFileBufSize); |
| 104 if (!m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize)) { | 105 if (m_pFile->ReadBlock(m_pBuf, m_dwCur, m_dwBufSize) != m_dwBufSize && |
| 106 !m_pFile->IsEOF()) { |
| 105 return FALSE; | 107 return FALSE; |
| 106 } | 108 } |
| 107 m_dwBufIndex = 0; | 109 m_dwBufIndex = 0; |
| 108 return TRUE; | 110 return TRUE; |
| 109 } | 111 } |
| 110 void CFX_SAXFile::Reset() { | 112 void CFX_SAXFile::Reset() { |
| 111 if (m_pBuf) { | 113 if (m_pBuf) { |
| 112 FX_Free(m_pBuf); | 114 FX_Free(m_pBuf); |
| 113 m_pBuf = nullptr; | 115 m_pBuf = nullptr; |
| 114 } | 116 } |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 void CFX_SAXReader::SkipCurrentNode() { | 710 void CFX_SAXReader::SkipCurrentNode() { |
| 709 if (!m_pCurItem) | 711 if (!m_pCurItem) |
| 710 return; | 712 return; |
| 711 | 713 |
| 712 m_pCurItem->m_bSkip = TRUE; | 714 m_pCurItem->m_bSkip = TRUE; |
| 713 } | 715 } |
| 714 | 716 |
| 715 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { | 717 void CFX_SAXReader::SetHandler(CXFA_SAXReaderHandler* pHandler) { |
| 716 m_pHandler = pHandler; | 718 m_pHandler = pHandler; |
| 717 } | 719 } |
| OLD | NEW |