Widen some uint32_t to size_t in CPDF_Stream Still need a checked cast, however, when setting /Length as it is unclear what the limit might be. Change-Id: I0feae83e5ca3d6ca847b502b88102ebcb0fa99c7 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91150 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp index 1ef1cdf..7fd6556 100644 --- a/core/fpdfapi/parser/cpdf_stream.cpp +++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -42,7 +42,7 @@ } CPDF_Stream::CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData, - uint32_t size, + size_t size, RetainPtr<CPDF_Dictionary> pDict) : m_pDict(std::move(pDict)) { TakeData(std::move(pData), size); @@ -147,14 +147,15 @@ } void CPDF_Stream::TakeData(std::unique_ptr<uint8_t, FxFreeDeleter> pData, - uint32_t size) { + size_t size) { m_bMemoryBased = true; m_pFile = nullptr; m_pDataBuf = std::move(pData); m_dwSize = size; if (!m_pDict) m_pDict = pdfium::MakeRetain<CPDF_Dictionary>(); - m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size)); + m_pDict->SetNewFor<CPDF_Number>("Length", + pdfium::base::checked_cast<int>(size)); } void CPDF_Stream::SetDataFromStringstream(fxcrt::ostringstream* stream) { @@ -168,7 +169,7 @@ bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, uint8_t* buf, - uint32_t size) const { + size_t size) const { if (!m_bMemoryBased && m_pFile) return m_pFile->ReadBlockAtOffset(buf, offset, size);
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h index eaf2696..497db20 100644 --- a/core/fpdfapi/parser/cpdf_stream.h +++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -34,20 +34,19 @@ bool WriteTo(IFX_ArchiveStream* archive, const CPDF_Encryptor* encryptor) const override; - uint32_t GetRawSize() const { return m_dwSize; } + size_t GetRawSize() const { return m_dwSize; } // Will be null in case when stream is not memory based. // Use CPDF_StreamAcc to data access in all cases. uint8_t* GetInMemoryRawData() const { return m_pDataBuf.get(); } - // Copies span into internally-owned buffer. + // Copies span or stream into internally-owned buffer. void SetData(pdfium::span<const uint8_t> pData); - - void TakeData(std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size); - void SetDataFromStringstream(fxcrt::ostringstream* stream); + void TakeData(std::unique_ptr<uint8_t, FxFreeDeleter> pData, size_t size); + // Set data and remove "Filter" and "DecodeParms" fields from stream - // dictionary. + // dictionary. Copies span or stream into internally-owned buffer. void SetDataAndRemoveFilter(pdfium::span<const uint8_t> pData); void SetDataFromStringstreamAndRemoveFilter(fxcrt::ostringstream* stream); @@ -56,7 +55,7 @@ void InitStreamFromFile(const RetainPtr<IFX_SeekableReadStream>& pFile, RetainPtr<CPDF_Dictionary> pDict); - bool ReadRawData(FX_FILESIZE offset, uint8_t* pBuf, uint32_t buf_size) const; + bool ReadRawData(FX_FILESIZE offset, uint8_t* pBuf, size_t buf_size) const; bool IsMemoryBased() const { return m_bMemoryBased; } bool HasFilter() const; @@ -66,7 +65,7 @@ CPDF_Stream(pdfium::span<const uint8_t> pData, RetainPtr<CPDF_Dictionary> pDict); CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData, - uint32_t size, + size_t size, RetainPtr<CPDF_Dictionary> pDict); ~CPDF_Stream() override; @@ -75,7 +74,7 @@ std::set<const CPDF_Object*>* pVisited) const override; bool m_bMemoryBased = true; - uint32_t m_dwSize = 0; + size_t m_dwSize = 0; RetainPtr<CPDF_Dictionary> m_pDict; std::unique_ptr<uint8_t, FxFreeDeleter> m_pDataBuf; RetainPtr<IFX_SeekableReadStream> m_pFile;