summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_parser.cpp
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-08-09 18:50:59 +0300
committerChromium commit bot <commit-bot@chromium.org>2017-08-09 16:10:23 +0000
commitd24b97ee1d065eff482355ea3ff82be59bb528b1 (patch)
treea736ae139525dddf6f1c62a1669d79d405782fea /core/fpdfapi/parser/cpdf_parser.cpp
parente13c4f887201e3cce33f927bfd6467e8e0263ea7 (diff)
downloadpdfium-d24b97ee1d065eff482355ea3ff82be59bb528b1.tar.xz
Unify of saving documents.chromium/3181
In the original code the method of writing of objects depends on a much unpredictable factors: as: 1) Is there an updated version of the at least one object in the document. 2) The password is changed. 3) Was this object loaded earlier. 4) The Object is compressed and document have a password. With these factors it is difficult to predict what will be the final file. To reduce volatility use only one method that works in all cases mentioned. This method is parse then serialize. Change-Id: I3d7dcadd10abffbad68d1f993f2dd60b039ed989 Reviewed-on: https://pdfium-review.googlesource.com/9572 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_parser.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp116
1 files changed, 0 insertions, 116 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 32c616c1c6..da51eb1c83 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -1258,122 +1258,6 @@ FX_FILESIZE CPDF_Parser::GetObjectSize(uint32_t objnum) const {
return *it - offset;
}
-std::vector<uint8_t> CPDF_Parser::GetIndirectBinary(uint32_t objnum) {
- std::vector<uint8_t> buffer;
- if (!IsValidObjectNumber(objnum))
- return buffer;
-
- if (GetObjectType(objnum) == ObjectType::kCompressed) {
- CFX_RetainPtr<CPDF_StreamAcc> pObjStream =
- GetObjectStream(m_ObjectInfo[objnum].pos);
- if (!pObjStream)
- return buffer;
-
- int32_t offset = GetStreamFirst(pObjStream);
- const uint8_t* pData = pObjStream->GetData();
- uint32_t totalsize = pObjStream->GetSize();
- auto file = pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(pData), static_cast<size_t>(totalsize), false);
- CPDF_SyntaxParser syntax;
- syntax.InitParser(file, 0);
-
- for (int i = GetStreamNCount(pObjStream); i > 0; --i) {
- uint32_t thisnum = syntax.GetDirectNum();
- uint32_t thisoff = syntax.GetDirectNum();
- if (thisnum != objnum)
- continue;
-
- size_t size = 0;
- if (i == 1) {
- size = totalsize - (thisoff + offset);
- } else {
- syntax.GetDirectNum(); // Skip nextnum.
- uint32_t nextoff = syntax.GetDirectNum();
- size = nextoff - thisoff;
- }
-
- buffer.resize(size);
- memcpy(buffer.data(), pData + thisoff + offset, size);
- break;
- }
- return buffer;
- }
-
- if (GetObjectType(objnum) != ObjectType::kNotCompressed)
- return buffer;
-
- FX_FILESIZE pos = m_ObjectInfo[objnum].pos;
- if (pos == 0)
- return buffer;
-
- FX_FILESIZE SavedPos = m_pSyntax->GetPos();
- m_pSyntax->SetPos(pos);
-
- bool bIsNumber;
- CFX_ByteString word = m_pSyntax->GetNextWord(&bIsNumber);
- if (!bIsNumber) {
- m_pSyntax->SetPos(SavedPos);
- return buffer;
- }
-
- uint32_t parser_objnum = FXSYS_atoui(word.c_str());
- if (parser_objnum && parser_objnum != objnum) {
- m_pSyntax->SetPos(SavedPos);
- return buffer;
- }
-
- word = m_pSyntax->GetNextWord(&bIsNumber);
- if (!bIsNumber) {
- m_pSyntax->SetPos(SavedPos);
- return buffer;
- }
-
- if (m_pSyntax->GetKeyword() != "obj") {
- m_pSyntax->SetPos(SavedPos);
- return buffer;
- }
-
- auto it = m_SortedOffset.find(pos);
- if (it == m_SortedOffset.end() || ++it == m_SortedOffset.end()) {
- m_pSyntax->SetPos(SavedPos);
- return buffer;
- }
-
- FX_FILESIZE nextoff = *it;
- bool bNextOffValid = false;
- if (nextoff != pos) {
- m_pSyntax->SetPos(nextoff);
- word = m_pSyntax->GetNextWord(&bIsNumber);
- if (word == "xref") {
- bNextOffValid = true;
- } else if (bIsNumber) {
- word = m_pSyntax->GetNextWord(&bIsNumber);
- if (bIsNumber && m_pSyntax->GetKeyword() == "obj") {
- bNextOffValid = true;
- }
- }
- }
-
- if (!bNextOffValid) {
- m_pSyntax->SetPos(pos);
- while (1) {
- if (m_pSyntax->GetKeyword() == "endobj")
- break;
-
- if (m_pSyntax->GetPos() == m_pSyntax->m_FileLen)
- break;
- }
- nextoff = m_pSyntax->GetPos();
- }
-
- size_t size = (uint32_t)(nextoff - pos);
- buffer.resize(size);
- m_pSyntax->SetPos(pos);
- m_pSyntax->ReadBlock(buffer.data(), size);
- m_pSyntax->SetPos(SavedPos);
- return buffer;
-}
-
std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObjectAt(
CPDF_IndirectObjectHolder* pObjList,
FX_FILESIZE pos,