diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-09-04 17:01:41 +0300 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-05 16:04:08 +0000 |
commit | 4fde70e28c6aff85ad30a958823e658678f5cfb6 (patch) | |
tree | baaeb84083b6f245940f58ae2331ee08aad0527e /core/fpdfapi/parser/cpdf_stream.cpp | |
parent | 16b77c7176313531609a3a062d286f555c4710a1 (diff) | |
download | pdfium-4fde70e28c6aff85ad30a958823e658678f5cfb6.tar.xz |
Fix length field in dictionary on create stream
The CPDF_stream constructors were not setting the "Length" into the stream dictionary.
The "Length" was being set by the SetData methods.
This CL fixes the constructor to properly set the "Length" field.
Change-Id: Iee1bd7f7a096d415ab01ee3d2f3416e19e87ece9
Reviewed-on: https://pdfium-review.googlesource.com/13010
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_stream.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp index 1c8660efb0..fadaec1b7e 100644 --- a/core/fpdfapi/parser/cpdf_stream.cpp +++ b/core/fpdfapi/parser/cpdf_stream.cpp @@ -22,7 +22,9 @@ CPDF_Stream::CPDF_Stream() {} CPDF_Stream::CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size, std::unique_ptr<CPDF_Dictionary> pDict) - : m_dwSize(size), m_pDict(std::move(pDict)), m_pDataBuf(std::move(pData)) {} + : m_pDict(std::move(pDict)) { + SetData(std::move(pData), size); +} CPDF_Stream::~CPDF_Stream() { m_ObjNum = kInvalidObjNum; @@ -54,14 +56,7 @@ void CPDF_Stream::InitStream(const uint8_t* pData, uint32_t size, std::unique_ptr<CPDF_Dictionary> pDict) { m_pDict = std::move(pDict); - m_bMemoryBased = true; - m_pFile = nullptr; - m_pDataBuf.reset(FX_Alloc(uint8_t, size)); - if (pData) - memcpy(m_pDataBuf.get(), pData, size); - m_dwSize = size; - if (m_pDict) - m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize)); + SetData(pData, size); } void CPDF_Stream::InitStreamFromFile( @@ -110,10 +105,19 @@ void CPDF_Stream::SetDataAndRemoveFilter(std::ostringstream* stream) { } void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { + std::unique_ptr<uint8_t, FxFreeDeleter> data_copy; + if (pData) { + data_copy.reset(FX_Alloc(uint8_t, size)); + memcpy(data_copy.get(), pData, size); + } + SetData(std::move(data_copy), size); +} + +void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData, + uint32_t size) { m_bMemoryBased = true; - m_pDataBuf.reset(FX_Alloc(uint8_t, size)); - if (pData) - memcpy(m_pDataBuf.get(), pData, size); + m_pFile = nullptr; + m_pDataBuf = std::move(pData); m_dwSize = size; if (!m_pDict) m_pDict = pdfium::MakeUnique<CPDF_Dictionary>(); |