summaryrefslogtreecommitdiff
path: root/core/fpdfapi/edit
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-07-25 02:28:35 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-25 02:28:35 +0000
commit70ddc1ca22ad44a77006491b604a75f6514a4aa8 (patch)
tree1aab47245a415069f425fac877fd361352fb2a27 /core/fpdfapi/edit
parent36b2059cae7fc851c9f35babd35ec82a7a5d9694 (diff)
downloadpdfium-70ddc1ca22ad44a77006491b604a75f6514a4aa8.tar.xz
Use document size instead of file size while parsing.
We should use document size instead of File size, because all offsets and sizes was read from document should take into account of header offset. Added some tests of parsing of documents with header offset. Also drop friendship of CPDF_SyntaxParser with CPDF_Parser. Change-Id: Iebec75ab2ee07fb644a6c653b4ef5c2e09af09fe Reviewed-on: https://pdfium-review.googlesource.com/35830 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r--core/fpdfapi/edit/cpdf_creator.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index aa8c751046..11b0628b01 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -17,6 +17,7 @@
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_security_handler.h"
#include "core/fpdfapi/parser/cpdf_string.h"
+#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
#include "core/fxcrt/fx_extension.h"
@@ -254,20 +255,19 @@ CPDF_Creator::Stage CPDF_Creator::WriteDoc_Stage1() {
}
m_iStage = Stage::kInitWriteObjs20;
} else {
- m_SavedOffset = m_pParser->GetFileAccess()->GetSize();
+ m_SavedOffset = m_pParser->GetSyntax()->GetDocumentSize();
m_iStage = Stage::kWriteIncremental15;
}
}
if (m_iStage == Stage::kWriteIncremental15) {
if (m_IsOriginal && m_SavedOffset > 0) {
- RetainPtr<IFX_SeekableReadStream> pSrcFile = m_pParser->GetFileAccess();
- std::vector<uint8_t> buffer(4096);
+ static constexpr FX_FILESIZE kBufferSize = 4096;
+ std::vector<uint8_t> buffer(kBufferSize);
FX_FILESIZE src_size = m_SavedOffset;
+ m_pParser->GetSyntax()->SetPos(0);
while (src_size) {
- uint32_t block_size = src_size > 4096 ? 4096 : src_size;
- if (!pSrcFile->ReadBlock(buffer.data(),
- m_Archive->CurrentOffset() - src_size,
- block_size)) {
+ const FX_FILESIZE block_size = std::min(kBufferSize, src_size);
+ if (!m_pParser->GetSyntax()->ReadBlock(buffer.data(), block_size)) {
return Stage::kInvalid;
}
if (!m_Archive->WriteBlock(buffer.data(), block_size))