diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-07-06 17:28:46 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-06 17:28:46 +0000 |
commit | dd1083b47c029d2540aceb246bf80f549781f62f (patch) | |
tree | 7e67b3daeb837eb50c5d72e99cf067538ce7df2c /core/fpdfapi/parser | |
parent | e3c4b205572eff5f12900f87d612f14a460e4997 (diff) | |
download | pdfium-dd1083b47c029d2540aceb246bf80f549781f62f.tar.xz |
Revert "Avoid duplicate data buffering in CPDF_SyntaxParser::ReadStream()."
This reverts commit 77f15f7883638a4ced131d74c053af10a5970ce9.
Reason for revert: Causes crbug.com/860210
Bug: chromium:860210
Original change's description:
> Avoid duplicate data buffering in CPDF_SyntaxParser::ReadStream().
>
> Allow sub-streams created from an IFX_SeekableReadStream to provide
> stream data without copying memory.
> The data will only reside in the top-level stream.
>
> For example:
> For file
> http://www.major-landrover.ru/upload/attachments/f/9/f96aab07dab04ae89c8a509ec1ef2b31.pdf
> (18 Mb)
>
> The memory usage is reduced by ~13 Mb.
>
> Change-Id: I2595c014d0fbe1fdd181cc04965cfd7d901c2d88
> Reviewed-on: https://pdfium-review.googlesource.com/35930
> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
> Reviewed-by: dsinclair <dsinclair@chromium.org>
TBR=tsepez@chromium.org,dsinclair@chromium.org,art-snake@yandex-team.ru
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I947fca17052765935a952a4f25ca48f6599c4af9
Reviewed-on: https://pdfium-review.googlesource.com/37210
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser.cpp | 67 |
1 files changed, 9 insertions, 58 deletions
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp index f8f36aee11..ec5ac70a29 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp @@ -34,37 +34,6 @@ namespace { enum class ReadStatus { Normal, Backslash, Octal, FinishOctal, CarriageReturn }; -class ReadableSubStream : public IFX_SeekableReadStream { - public: - ReadableSubStream(const RetainPtr<IFX_SeekableReadStream>& pFileRead, - FX_FILESIZE part_offset, - FX_FILESIZE part_size) - : m_pFileRead(pFileRead), - m_PartOffset(part_offset), - m_PartSize(part_size) {} - - ~ReadableSubStream() override = default; - - // IFX_SeekableReadStream overrides: - bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { - FX_SAFE_FILESIZE safe_end = offset; - safe_end += size; - // Check that requested range is valid, to prevent calling of ReadBlock - // of original m_pFileRead with incorrect params. - if (!safe_end.IsValid() || safe_end.ValueOrDie() > m_PartSize) - return false; - - return m_pFileRead->ReadBlock(buffer, m_PartOffset + offset, size); - } - - FX_FILESIZE GetSize() override { return m_PartSize; } - - private: - RetainPtr<IFX_SeekableReadStream> m_pFileRead; - FX_FILESIZE m_PartOffset; - FX_FILESIZE m_PartSize; -}; - } // namespace // static @@ -608,6 +577,7 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream( ToNextLine(); const FX_FILESIZE streamStartPos = GetPos(); + std::unique_ptr<uint8_t, FxFreeDeleter> pData; if (len > 0) { FX_SAFE_FILESIZE pos = GetPos(); pos += len; @@ -615,18 +585,12 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream( len = -1; } - RetainPtr<IFX_SeekableReadStream> data; if (len > 0) { - // Check data availability first to allow the Validator to request data + pData.reset(FX_Alloc(uint8_t, len)); + // We should try read data first to allow the Validator to request data // smoothly, without jumps. - if (!GetValidator()->CheckDataRangeAndRequestIfUnavailable( - m_HeaderOffset + GetPos(), len)) { + if (!ReadBlock(pData.get(), len)) return nullptr; - } - - data = pdfium::MakeRetain<ReadableSubStream>( - GetValidator(), m_HeaderOffset + GetPos(), len); - SetPos(GetPos() + len); } const ByteStringView kEndStreamStr("endstream"); @@ -647,7 +611,7 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream( // specified length, it signals the end of stream. if (memcmp(m_WordBuffer, kEndStreamStr.raw_str(), kEndStreamStr.GetLength()) != 0) { - data.Reset(); + pData.reset(); len = -1; SetPos(streamStartPos); } @@ -664,27 +628,14 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream( ASSERT(len >= 0); if (len > 0) { SetPos(streamStartPos); - // Check data availability first to allow the Validator to request data - // smoothly, without jumps. - if (!GetValidator()->CheckDataRangeAndRequestIfUnavailable( - m_HeaderOffset + GetPos(), len)) { + pData.reset(FX_Alloc(uint8_t, len)); + if (!ReadBlock(pData.get(), len)) return nullptr; - } - - data = pdfium::MakeRetain<ReadableSubStream>( - GetValidator(), m_HeaderOffset + GetPos(), len); - SetPos(GetPos() + len); } } - auto pStream = pdfium::MakeUnique<CPDF_Stream>(); - if (data) { - pStream->InitStreamFromFile(data, std::move(pDict)); - } else { - DCHECK(!len); - // Empty stream - pStream->InitStream(nullptr, 0, std::move(pDict)); - } + auto pStream = + pdfium::MakeUnique<CPDF_Stream>(std::move(pData), len, std::move(pDict)); const FX_FILESIZE end_stream_offset = GetPos(); memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); GetNextWordInternal(nullptr); |