diff options
author | tsepez <tsepez@chromium.org> | 2016-12-07 09:21:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-07 09:21:18 -0800 |
commit | 833619b4441915c7c55085d44b3221eaef0d9800 (patch) | |
tree | 68bf76e83078223ba03f490c2c13f484e40154d4 /core/fpdfapi/parser/cpdf_parser.cpp | |
parent | 8f875507a986d10335e40a5f7c1679aff9770d0a (diff) | |
download | pdfium-833619b4441915c7c55085d44b3221eaef0d9800.tar.xz |
Refcount all the IFX_ stream classes all the time.
We can remove a lot of "bOwnsStream" logic in the process.
Always pass these by const reference, in case the called method
wants to hang on to the stream (one exception is where we stick
a raw pointer into a void* slot in a context from another layer).
Review-Url: https://codereview.chromium.org/2451493002
Diffstat (limited to 'core/fpdfapi/parser/cpdf_parser.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser.cpp | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 1fae0d641c..47c5c4eab4 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -52,7 +52,6 @@ int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) { CPDF_Parser::CPDF_Parser() : m_pDocument(nullptr), m_bHasParsed(false), - m_bOwnFileRead(true), m_bXRefStream(false), m_bVersionUpdated(false), m_FileVersion(0), @@ -64,11 +63,6 @@ CPDF_Parser::CPDF_Parser() CPDF_Parser::~CPDF_Parser() { ReleaseEncryptHandler(); SetEncryptDictionary(nullptr); - - if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) { - m_pSyntax->m_pFileAccess->Release(); - m_pSyntax->m_pFileAccess = nullptr; - } } uint32_t CPDF_Parser::GetLastObjNum() const { @@ -109,7 +103,7 @@ CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() { return m_pSyntax->m_pCryptoHandler.get(); } -IFX_SeekableReadStream* CPDF_Parser::GetFileAccess() const { +CFX_RetainPtr<IFX_SeekableReadStream> CPDF_Parser::GetFileAccess() const { return m_pSyntax->m_pFileAccess; } @@ -129,31 +123,30 @@ void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { m_ObjectInfo[objnum - 1].pos = 0; } -CPDF_Parser::Error CPDF_Parser::StartParse(IFX_SeekableReadStream* pFileAccess, - CPDF_Document* pDocument) { +CPDF_Parser::Error CPDF_Parser::StartParse( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess, + CPDF_Document* pDocument) { ASSERT(!m_bHasParsed); m_bHasParsed = true; - m_bXRefStream = false; m_LastXRefOffset = 0; - m_bOwnFileRead = true; int32_t offset = GetHeaderOffset(pFileAccess); - if (offset == -1) { - if (pFileAccess) - pFileAccess->Release(); + if (offset == -1) return FORMAT_ERROR; - } + m_pSyntax->InitParser(pFileAccess, offset); uint8_t ch; if (!m_pSyntax->GetCharAt(5, ch)) return FORMAT_ERROR; + if (std::isdigit(ch)) m_FileVersion = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)) * 10; if (!m_pSyntax->GetCharAt(7, ch)) return FORMAT_ERROR; + if (std::isdigit(ch)) m_FileVersion += FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)); @@ -1124,10 +1117,10 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject( if (!pObjStream) return nullptr; - ScopedFileStream file(IFX_MemoryStream::Create( - (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), false)); + CFX_RetainPtr<IFX_MemoryStream> file = IFX_MemoryStream::Create( + (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), false); CPDF_SyntaxParser syntax; - syntax.InitParser(file.get(), 0); + syntax.InitParser(file, 0); const int32_t offset = GetStreamFirst(pObjStream); // Read object numbers from |pObjStream| into a cache. @@ -1203,11 +1196,11 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum, int32_t offset = GetStreamFirst(pObjStream); const uint8_t* pData = pObjStream->GetData(); uint32_t totalsize = pObjStream->GetSize(); - ScopedFileStream file( - IFX_MemoryStream::Create((uint8_t*)pData, (size_t)totalsize, false)); - + CFX_RetainPtr<IFX_MemoryStream> file = + IFX_MemoryStream::Create((uint8_t*)pData, (size_t)totalsize, false); CPDF_SyntaxParser syntax; - syntax.InitParser(file.get(), 0); + syntax.InitParser(file, 0); + for (int i = GetStreamNCount(pObjStream); i > 0; --i) { uint32_t thisnum = syntax.GetDirectNum(); uint32_t thisoff = syntax.GetDirectNum(); @@ -1420,8 +1413,9 @@ uint32_t CPDF_Parser::GetPermissions() const { return dwPermission; } -bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, - uint32_t offset) { +bool CPDF_Parser::IsLinearizedFile( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess, + uint32_t offset) { m_pSyntax->InitParser(pFileAccess, offset); m_pSyntax->RestorePos(m_pSyntax->m_HeaderOffset + 9); @@ -1454,13 +1448,11 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, } CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( - IFX_SeekableReadStream* pFileAccess, + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess, CPDF_Document* pDocument) { ASSERT(!m_bHasParsed); - m_bXRefStream = false; m_LastXRefOffset = 0; - m_bOwnFileRead = true; int32_t offset = GetHeaderOffset(pFileAccess); if (offset == -1) @@ -1474,7 +1466,6 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( m_pDocument = pDocument; FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos(); - bool bXRefRebuilt = false; bool bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, false); if (!bLoadV4 && !LoadCrossRefV5(&dwFirstXRefOffset, true)) { |