diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-08-29 19:32:47 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-29 19:32:47 +0000 |
commit | 1934a24ffdd8cd27b67fda6dc81cd4420d024db0 (patch) | |
tree | 514e968715388b7a86ee66bc575d2e21f11fceb7 | |
parent | b2b1f55214688d5e3bfd5015e0a4829d2f314c27 (diff) | |
download | pdfium-1934a24ffdd8cd27b67fda6dc81cd4420d024db0.tar.xz |
Use pdfium::span<> in fpdf_parser_decode.h helper functions.
Change-Id: Ib0a2bd21fe4304163cf9c080e07475e7c033c299
Reviewed-on: https://pdfium-review.googlesource.com/41570
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r-- | core/fpdfapi/edit/cpdf_flateencoder.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamparser.cpp | 23 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream_acc.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.cpp | 135 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.h | 40 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp | 4 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_flatemodule.cpp | 34 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_flatemodule.h | 3 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_rle_unittest.cpp | 14 | ||||
-rw-r--r-- | fpdfsdk/fpdf_attachment.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_localemgr.cpp | 40 |
12 files changed, 144 insertions, 159 deletions
diff --git a/core/fpdfapi/edit/cpdf_flateencoder.cpp b/core/fpdfapi/edit/cpdf_flateencoder.cpp index 573c141ff2..a42b256ed2 100644 --- a/core/fpdfapi/edit/cpdf_flateencoder.cpp +++ b/core/fpdfapi/edit/cpdf_flateencoder.cpp @@ -40,7 +40,7 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(const CPDF_Stream* pStream, // TODO(thestig): Move to Init() and check return value. uint8_t* buffer = nullptr; - ::FlateEncode(m_pAcc->GetData(), m_pAcc->GetSize(), &buffer, &m_dwSize); + ::FlateEncode(m_pAcc->GetSpan(), &buffer, &m_dwSize); m_pData = std::unique_ptr<uint8_t, FxFreeDeleter>(buffer); m_pClonedDict = ToDictionary(pStream->GetDict()->Clone()); diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp index 3d086b37ff..0d45ed0323 100644 --- a/core/fpdfapi/page/cpdf_streamparser.cpp +++ b/core/fpdfapi/page/cpdf_streamparser.cpp @@ -61,8 +61,7 @@ uint32_t DecodeAllScanlines(std::unique_ptr<CCodec_ScanlineDecoder> pDecoder, return pDecoder->GetSrcOffset(); } -uint32_t DecodeInlineStream(const uint8_t* src_buf, - uint32_t limit, +uint32_t DecodeInlineStream(pdfium::span<const uint8_t> src_span, int width, int height, const ByteString& decoder, @@ -71,30 +70,29 @@ uint32_t DecodeInlineStream(const uint8_t* src_buf, uint32_t* dest_size) { if (decoder == "CCITTFaxDecode" || decoder == "CCF") { std::unique_ptr<CCodec_ScanlineDecoder> pDecoder = - CreateFaxDecoder({src_buf, limit}, width, height, pParam); + CreateFaxDecoder(src_span, width, height, pParam); return DecodeAllScanlines(std::move(pDecoder), dest_buf, dest_size); } if (decoder == "ASCII85Decode" || decoder == "A85") - return A85Decode(src_buf, limit, dest_buf, dest_size); + return A85Decode(src_span, dest_buf, dest_size); if (decoder == "ASCIIHexDecode" || decoder == "AHx") - return HexDecode(src_buf, limit, dest_buf, dest_size); + return HexDecode(src_span, dest_buf, dest_size); if (decoder == "FlateDecode" || decoder == "Fl") { - return FlateOrLZWDecode(false, src_buf, limit, pParam, *dest_size, dest_buf, + return FlateOrLZWDecode(false, src_span, pParam, *dest_size, dest_buf, dest_size); } if (decoder == "LZWDecode" || decoder == "LZW") { - return FlateOrLZWDecode(true, src_buf, limit, pParam, 0, dest_buf, - dest_size); + return FlateOrLZWDecode(true, src_span, pParam, 0, dest_buf, dest_size); } if (decoder == "DCTDecode" || decoder == "DCT") { std::unique_ptr<CCodec_ScanlineDecoder> pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( - {src_buf, limit}, width, height, 0, + src_span, width, height, 0, !pParam || pParam->GetIntegerFor("ColorTransform", 1)); return DecodeAllScanlines(std::move(pDecoder), dest_buf, dest_size); } if (decoder == "RunLengthDecode" || decoder == "RL") - return RunLengthDecode(src_buf, limit, dest_buf, dest_size); + return RunLengthDecode(src_span, dest_buf, dest_size); *dest_size = 0; *dest_buf = 0; return 0xFFFFFFFF; @@ -185,9 +183,8 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream( } else { uint8_t* pIgnore = nullptr; uint32_t dwDestSize = OrigSize; - dwStreamSize = - DecodeInlineStream(&m_pBuf[m_Pos], m_pBuf.size() - m_Pos, width, height, - Decoder, pParam, &pIgnore, &dwDestSize); + dwStreamSize = DecodeInlineStream(m_pBuf.subspan(m_Pos), width, height, + Decoder, pParam, &pIgnore, &dwDestSize); FX_Free(pIgnore); if (static_cast<int>(dwStreamSize) < 0) return nullptr; diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp index 18d0b35107..1083e3177e 100644 --- a/core/fpdfapi/parser/cpdf_stream_acc.cpp +++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp @@ -47,7 +47,7 @@ void CPDF_StreamAcc::LoadAllData(bool bRawAccess, if (bProcessRawData) { m_pData = pSrcData; m_dwSize = dwSrcSize; - } else if (!PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), + } else if (!PDF_DataDecode({pSrcData, dwSrcSize}, m_pStream->GetDict(), estimated_size, bImageAcc, &m_pData, &m_dwSize, &m_ImageDecoder, &m_pImageParam)) { m_pData = pSrcData; diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 8143517029..de93acf938 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -83,20 +83,19 @@ const uint16_t PDFDocEncoding[256] = { 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}; -uint32_t A85Decode(const uint8_t* src_buf, - uint32_t src_size, +uint32_t A85Decode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { *dest_size = 0; *dest_buf = nullptr; - if (src_size == 0) + if (src_span.empty()) return 0; // Count legal characters and zeros. uint32_t zcount = 0; uint32_t pos = 0; - while (pos < src_size) { - uint8_t ch = src_buf[pos]; + while (pos < src_span.size()) { + uint8_t ch = src_span[pos]; if (ch == 'z') { zcount++; } else if ((ch < '!' || ch > 'u') && !PDFCharIsLineEnding(ch) && @@ -119,8 +118,8 @@ uint32_t A85Decode(const uint8_t* src_buf, size_t state = 0; uint32_t res = 0; pos = 0; - while (pos < src_size) { - uint8_t ch = src_buf[pos++]; + while (pos < src_span.size()) { + uint8_t ch = src_span[pos++]; if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') continue; @@ -155,30 +154,29 @@ uint32_t A85Decode(const uint8_t* src_buf, for (size_t i = 0; i < state - 1; ++i) (*dest_buf)[(*dest_size)++] = static_cast<uint8_t>(res >> (3 - i) * 8); } - if (pos < src_size && src_buf[pos] == '>') + if (pos < src_span.size() && src_span[pos] == '>') ++pos; return pos; } -uint32_t HexDecode(const uint8_t* src_buf, - uint32_t src_size, +uint32_t HexDecode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { *dest_size = 0; - if (src_size == 0) { + if (src_span.empty()) { *dest_buf = nullptr; return 0; } uint32_t i = 0; // Find the end of data. - while (i < src_size && src_buf[i] != '>') + while (i < src_span.size() && src_span[i] != '>') ++i; *dest_buf = FX_Alloc(uint8_t, i / 2 + 1); bool bFirst = true; - for (i = 0; i < src_size; ++i) { - uint8_t ch = src_buf[i]; + for (i = 0; i < src_span.size(); ++i) { + uint8_t ch = src_span[i]; if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') continue; @@ -201,24 +199,23 @@ uint32_t HexDecode(const uint8_t* src_buf, return i; } -uint32_t RunLengthDecode(const uint8_t* src_buf, - uint32_t src_size, +uint32_t RunLengthDecode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { - uint32_t i = 0; + size_t i = 0; *dest_size = 0; - while (i < src_size) { - if (src_buf[i] == 128) + while (i < src_span.size()) { + if (src_span[i] == 128) break; uint32_t old = *dest_size; - if (src_buf[i] < 128) { - *dest_size += src_buf[i] + 1; + if (src_span[i] < 128) { + *dest_size += src_span[i] + 1; if (*dest_size < old) return FX_INVALID_OFFSET; - i += src_buf[i] + 2; + i += src_span[i] + 2; } else { - *dest_size += 257 - src_buf[i]; + *dest_size += 257 - src_span[i]; if (*dest_size < old) return FX_INVALID_OFFSET; i += 2; @@ -230,31 +227,31 @@ uint32_t RunLengthDecode(const uint8_t* src_buf, *dest_buf = FX_Alloc(uint8_t, *dest_size); i = 0; int dest_count = 0; - while (i < src_size) { - if (src_buf[i] == 128) + while (i < src_span.size()) { + if (src_span[i] == 128) break; - if (src_buf[i] < 128) { - uint32_t copy_len = src_buf[i] + 1; - uint32_t buf_left = src_size - i - 1; + if (src_span[i] < 128) { + uint32_t copy_len = src_span[i] + 1; + uint32_t buf_left = src_span.size() - i - 1; if (buf_left < copy_len) { uint32_t delta = copy_len - buf_left; copy_len = buf_left; memset(*dest_buf + dest_count + copy_len, '\0', delta); } - memcpy(*dest_buf + dest_count, src_buf + i + 1, copy_len); - dest_count += src_buf[i] + 1; - i += src_buf[i] + 2; + memcpy(*dest_buf + dest_count, &src_span[i + 1], copy_len); + dest_count += src_span[i] + 1; + i += src_span[i] + 2; } else { int fill = 0; - if (i < src_size - 1) - fill = src_buf[i + 1]; - memset(*dest_buf + dest_count, fill, 257 - src_buf[i]); - dest_count += 257 - src_buf[i]; + if (i < src_span.size() - 1) + fill = src_span[i + 1]; + memset(*dest_buf + dest_count, fill, 257 - src_span[i]); + dest_count += 257 - src_span[i]; i += 2; } } - return std::min(i + 1, src_size); + return std::min(i + 1, src_span.size()); } std::unique_ptr<CCodec_ScanlineDecoder> CreateFaxDecoder( @@ -308,8 +305,7 @@ std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder( } uint32_t FlateOrLZWDecode(bool bLZW, - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_span, const CPDF_Dictionary* pParams, uint32_t estimated_size, uint8_t** dest_buf, @@ -329,12 +325,11 @@ uint32_t FlateOrLZWDecode(bool bLZW, return FX_INVALID_OFFSET; } return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( - bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, - BitsPerComponent, Columns, estimated_size, dest_buf, dest_size); + bLZW, src_span, bEarlyChange, predictor, Colors, BitsPerComponent, + Columns, estimated_size, dest_buf, dest_size); } -bool PDF_DataDecode(const uint8_t* src_buf, - uint32_t src_size, +bool PDF_DataDecode(pdfium::span<const uint8_t> src_span, const CPDF_Dictionary* pDict, uint32_t last_estimated_size, bool bImageAcc, @@ -362,8 +357,8 @@ bool PDF_DataDecode(const uint8_t* src_buf, DecoderArray.push_back( {pDecoder->GetString(), pParams ? pParams->GetDict() : nullptr}); } - uint8_t* last_buf = const_cast<uint8_t*>(src_buf); - uint32_t last_size = src_size; + pdfium::span<uint8_t> last_span(const_cast<uint8_t*>(src_span.data()), + src_span.size()); size_t nSize = DecoderArray.size(); for (size_t i = 0; i < nSize; ++i) { int estimated_size = i == nSize - 1 ? last_estimated_size : 0; @@ -377,29 +372,29 @@ bool PDF_DataDecode(const uint8_t* src_buf, if (decoder == "FlateDecode" || decoder == "Fl") { if (bImageAcc && i == nSize - 1) { *ImageEncoding = "FlateDecode"; - *dest_buf = last_buf; - *dest_size = last_size; + *dest_buf = last_span.data(); + *dest_size = last_span.size(); *pImageParams = pParam; return true; } - offset = FlateOrLZWDecode(false, last_buf, last_size, pParam, - estimated_size, &new_buf, &new_size); + offset = FlateOrLZWDecode(false, last_span, pParam, estimated_size, + &new_buf, &new_size); } else if (decoder == "LZWDecode" || decoder == "LZW") { - offset = FlateOrLZWDecode(true, last_buf, last_size, pParam, - estimated_size, &new_buf, &new_size); + offset = FlateOrLZWDecode(true, last_span, pParam, estimated_size, + &new_buf, &new_size); } else if (decoder == "ASCII85Decode" || decoder == "A85") { - offset = A85Decode(last_buf, last_size, &new_buf, &new_size); + offset = A85Decode(last_span, &new_buf, &new_size); } else if (decoder == "ASCIIHexDecode" || decoder == "AHx") { - offset = HexDecode(last_buf, last_size, &new_buf, &new_size); + offset = HexDecode(last_span, &new_buf, &new_size); } else if (decoder == "RunLengthDecode" || decoder == "RL") { if (bImageAcc && i == nSize - 1) { *ImageEncoding = "RunLengthDecode"; - *dest_buf = last_buf; - *dest_size = last_size; + *dest_buf = last_span.data(); + *dest_size = last_span.size(); *pImageParams = pParam; return true; } - offset = RunLengthDecode(last_buf, last_size, &new_buf, &new_size); + offset = RunLengthDecode(last_span, &new_buf, &new_size); } else { // If we get here, assume it's an image decoder. if (decoder == "DCT") @@ -408,23 +403,25 @@ bool PDF_DataDecode(const uint8_t* src_buf, decoder = "CCITTFaxDecode"; *ImageEncoding = std::move(decoder); *pImageParams = pParam; - *dest_buf = last_buf; - *dest_size = last_size; + *dest_buf = last_span.data(); + *dest_size = last_span.size(); return true; } - if (last_buf != src_buf) - FX_Free(last_buf); + if (last_span.data() != src_span.data()) { + auto* temp = last_span.data(); + last_span = {}; // Spans can't outlive their data. + FX_Free(temp); + } if (offset == FX_INVALID_OFFSET) { FX_Free(new_buf); return false; } - last_buf = new_buf; - last_size = new_size; + last_span = {new_buf, new_size}; } ImageEncoding->clear(); *pImageParams = nullptr; - *dest_buf = last_buf; - *dest_size = last_size; + *dest_buf = last_span.data(); + *dest_size = last_span.size(); return true; } @@ -554,20 +551,18 @@ ByteString PDF_EncodeString(const ByteString& src, bool bHex) { return ByteString(result); } -bool FlateEncode(const uint8_t* src_buf, - uint32_t src_size, +bool FlateEncode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); - return pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, - dest_size); + return pEncoders->GetFlateModule()->Encode(src_span.data(), src_span.size(), + dest_buf, dest_size); } -uint32_t FlateDecode(const uint8_t* src_buf, - uint32_t src_size, +uint32_t FlateDecode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); return pEncoders->GetFlateModule()->FlateOrLZWDecode( - false, src_buf, src_size, false, 0, 0, 0, 0, 0, dest_buf, dest_size); + false, src_span, false, 0, 0, 0, 0, 0, dest_buf, dest_size); } diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h index da228d223d..1484dd7cf0 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.h +++ b/core/fpdfapi/parser/fpdf_parser_decode.h @@ -11,6 +11,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/unowned_ptr.h" +#include "third_party/base/span.h" class CCodec_ScanlineDecoder; class CPDF_Dictionary; @@ -23,21 +24,6 @@ WideString PDF_DecodeText(const uint8_t* pData, uint32_t size); WideString PDF_DecodeText(const ByteString& bstr); ByteString PDF_EncodeText(const WideString& str); -bool FlateEncode(const uint8_t* src_buf, - uint32_t src_size, - uint8_t** dest_buf, - uint32_t* dest_size); - -uint32_t FlateDecode(const uint8_t* src_buf, - uint32_t src_size, - uint8_t** dest_buf, - uint32_t* dest_size); - -uint32_t RunLengthDecode(const uint8_t* src_buf, - uint32_t src_size, - uint8_t** dest_buf, - uint32_t* dest_size); - std::unique_ptr<CCodec_ScanlineDecoder> CreateFaxDecoder( pdfium::span<const uint8_t> src_span, int width, @@ -52,26 +38,34 @@ std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder( int bpc, const CPDF_Dictionary* pParams); -uint32_t A85Decode(const uint8_t* src_buf, - uint32_t src_size, +bool FlateEncode(pdfium::span<const uint8_t> src_span, + uint8_t** dest_buf, + uint32_t* dest_size); + +uint32_t FlateDecode(pdfium::span<const uint8_t> src_span, + uint8_t** dest_buf, + uint32_t* dest_size); + +uint32_t RunLengthDecode(pdfium::span<const uint8_t> src_span, + uint8_t** dest_buf, + uint32_t* dest_size); + +uint32_t A85Decode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size); -uint32_t HexDecode(const uint8_t* src_buf, - uint32_t src_size, +uint32_t HexDecode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size); uint32_t FlateOrLZWDecode(bool bLZW, - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_span, const CPDF_Dictionary* pParams, uint32_t estimated_size, uint8_t** dest_buf, uint32_t* dest_size); -bool PDF_DataDecode(const uint8_t* src_buf, - uint32_t src_size, +bool PDF_DataDecode(pdfium::span<const uint8_t> src_span, const CPDF_Dictionary* pDict, uint32_t estimated_size, bool bImageAcc, diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp index 3a48e80de8..d7256f0da5 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp @@ -39,7 +39,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateEncode) { const pdfium::StrFuncTestData& data = flate_encode_cases[i]; unsigned char* buf = nullptr; uint32_t buf_size; - EXPECT_TRUE(FlateEncode(data.input, data.input_size, &buf, &buf_size)); + EXPECT_TRUE(FlateEncode({data.input, data.input_size}, &buf, &buf_size)); ASSERT_TRUE(buf); EXPECT_EQ(data.expected_size, buf_size) << " for case " << i; if (data.expected_size != buf_size) @@ -77,7 +77,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) { unsigned char* buf = nullptr; uint32_t buf_size; EXPECT_EQ(data.processed_size, - FlateDecode(data.input, data.input_size, &buf, &buf_size)) + FlateDecode({data.input, data.input_size}, &buf, &buf_size)) << " for case " << i; ASSERT_TRUE(buf); EXPECT_EQ(data.expected_size, buf_size) << " for case " << i; diff --git a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp index 9ab4958825..aa37b796e2 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp @@ -31,7 +31,7 @@ TEST(fpdf_parser_decode, A85Decode) { uint8_t* result = nullptr; uint32_t result_size = 0; EXPECT_EQ(ptr->processed_size, - A85Decode(ptr->input, ptr->input_size, &result, &result_size)) + A85Decode({ptr->input, ptr->input_size}, &result, &result_size)) << "for case " << i; ASSERT_EQ(ptr->expected_size, result_size); for (size_t j = 0; j < result_size; ++j) { @@ -66,7 +66,7 @@ TEST(fpdf_parser_decode, HexDecode) { uint8_t* result = nullptr; uint32_t result_size = 0; EXPECT_EQ(ptr->processed_size, - HexDecode(ptr->input, ptr->input_size, &result, &result_size)) + HexDecode({ptr->input, ptr->input_size}, &result, &result_size)) << "for case " << i; ASSERT_EQ(ptr->expected_size, result_size); for (size_t j = 0; j < result_size; ++j) { diff --git a/core/fxcodec/codec/ccodec_flatemodule.cpp b/core/fxcodec/codec/ccodec_flatemodule.cpp index 0a4baea38f..81be9b02d7 100644 --- a/core/fxcodec/codec/ccodec_flatemodule.cpp +++ b/core/fxcodec/codec/ccodec_flatemodule.cpp @@ -781,17 +781,17 @@ std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FlateModule::CreateDecoder( BitsPerComponent, Columns); } -uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, - const uint8_t* src_buf, - uint32_t src_size, - bool bEarlyChange, - int predictor, - int Colors, - int BitsPerComponent, - int Columns, - uint32_t estimated_size, - uint8_t** dest_buf, - uint32_t* dest_size) { +uint32_t CCodec_FlateModule::FlateOrLZWDecode( + bool bLZW, + pdfium::span<const uint8_t> src_span, + bool bEarlyChange, + int predictor, + int Colors, + int BitsPerComponent, + int Columns, + uint32_t estimated_size, + uint8_t** dest_buf, + uint32_t* dest_size) { *dest_buf = nullptr; uint32_t offset = 0; PredictorType predictor_type = GetPredictor(predictor); @@ -799,19 +799,19 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, if (bLZW) { auto decoder = pdfium::MakeUnique<CLZWDecoder>(); *dest_size = 0xFFFFFFFF; - offset = src_size; - int err = - decoder->Decode(nullptr, *dest_size, src_buf, offset, bEarlyChange); + offset = src_span.size(); + int err = decoder->Decode(nullptr, *dest_size, src_span.data(), offset, + bEarlyChange); if (err || *dest_size == 0 || *dest_size + 1 < *dest_size) return FX_INVALID_OFFSET; decoder = pdfium::MakeUnique<CLZWDecoder>(); *dest_buf = FX_Alloc(uint8_t, *dest_size + 1); (*dest_buf)[*dest_size] = '\0'; - decoder->Decode(*dest_buf, *dest_size, src_buf, offset, bEarlyChange); + decoder->Decode(*dest_buf, *dest_size, src_span.data(), offset, + bEarlyChange); } else { - FlateUncompress(pdfium::make_span(src_buf, src_size), estimated_size, - *dest_buf, *dest_size, offset); + FlateUncompress(src_span, estimated_size, *dest_buf, *dest_size, offset); } bool ret = false; diff --git a/core/fxcodec/codec/ccodec_flatemodule.h b/core/fxcodec/codec/ccodec_flatemodule.h index dab34be8a0..11281522e0 100644 --- a/core/fxcodec/codec/ccodec_flatemodule.h +++ b/core/fxcodec/codec/ccodec_flatemodule.h @@ -28,8 +28,7 @@ class CCodec_FlateModule { int Columns); uint32_t FlateOrLZWDecode(bool bLZW, - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> src_buf, bool bEarlyChange, int predictor, int Colors, diff --git a/core/fxcodec/codec/fx_codec_rle_unittest.cpp b/core/fxcodec/codec/fx_codec_rle_unittest.cpp index 7b0af90819..47067cb030 100644 --- a/core/fxcodec/codec/fx_codec_rle_unittest.cpp +++ b/core/fxcodec/codec/fx_codec_rle_unittest.cpp @@ -74,7 +74,7 @@ TEST(fxcodec, RLETestNormalInputs) { pEncoders->RunLengthEncode(src_buf_1, src_size, &dest_buf, &dest_size)); uint8_t* decoded_buf = nullptr; uint32_t decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; @@ -88,7 +88,7 @@ TEST(fxcodec, RLETestNormalInputs) { pEncoders->RunLengthEncode(src_buf_2, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; @@ -102,7 +102,7 @@ TEST(fxcodec, RLETestNormalInputs) { pEncoders->RunLengthEncode(src_buf_3, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; @@ -143,7 +143,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_1, src_size, &dest_buf, &dest_size)); uint8_t* decoded_buf = nullptr; uint32_t decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; @@ -157,7 +157,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_2, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; @@ -171,7 +171,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_3, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; @@ -185,7 +185,7 @@ TEST(fxcodec, RLETestFullLengthInputs) { pEncoders->RunLengthEncode(src_buf_4, src_size, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; - RunLengthDecode(dest_buf, dest_size, &decoded_buf, &decoded_size); + RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); ASSERT_EQ(src_size, decoded_size); for (uint32_t i = 0; i < src_size; i++) EXPECT_EQ(src_buf_4[i], decoded_buf[i]) << " at " << i; diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp index 6a4faf6c65..f3c1c83cf9 100644 --- a/fpdfsdk/fpdf_attachment.cpp +++ b/fpdfsdk/fpdf_attachment.cpp @@ -29,7 +29,7 @@ constexpr char kChecksumKey[] = "CheckSum"; ByteString CFXByteStringHexDecode(const ByteString& bsHex) { uint8_t* result = nullptr; uint32_t size = 0; - HexDecode(bsHex.raw_str(), bsHex.GetLength(), &result, &size); + HexDecode(bsHex.AsRawSpan(), &result, &size); ByteString bsDecoded(result, size); FX_Free(result); return bsDecoded; diff --git a/xfa/fxfa/parser/cxfa_localemgr.cpp b/xfa/fxfa/parser/cxfa_localemgr.cpp index a6d5b148d8..55ba04bbb0 100644 --- a/xfa/fxfa/parser/cxfa_localemgr.cpp +++ b/xfa/fxfa/parser/cxfa_localemgr.cpp @@ -1066,16 +1066,16 @@ const uint8_t g_ruRU_Locale[] = { 0xB3, 0x85, 0xFA, 0x59, 0x2A, 0x7A, 0xFF, 0x3D, 0xC4, 0x3F, 0xDE, 0xCB, 0x8B, 0xC4}; -std::unique_ptr<LocaleIface> GetLocaleFromBuffer(const uint8_t* pBuf, - int nBufLen) { - if (!pBuf || nBufLen <= 0) +std::unique_ptr<LocaleIface> GetLocaleFromBuffer( + pdfium::span<const uint8_t> src_span) { + if (src_span.empty()) return nullptr; uint8_t* pOut = nullptr; uint32_t dwSize; CCodec_ModuleMgr* pCodecMgr = CPDF_ModuleMgr::Get()->GetCodecModule(); - pCodecMgr->GetFlateModule()->FlateOrLZWDecode(false, pBuf, nBufLen, true, 0, - 0, 0, 0, 0, &pOut, &dwSize); + pCodecMgr->GetFlateModule()->FlateOrLZWDecode(false, src_span, true, 0, 0, 0, + 0, 0, &pOut, &dwSize); if (!pOut) return nullptr; @@ -1164,36 +1164,36 @@ LocaleIface* CXFA_LocaleMgr::GetDefLocale() { std::unique_ptr<LocaleIface> CXFA_LocaleMgr::GetLocale(uint16_t lcid) { switch (lcid) { case FX_LANG_zh_CN: - return GetLocaleFromBuffer(g_zhCN_Locale, sizeof(g_zhCN_Locale)); + return GetLocaleFromBuffer(g_zhCN_Locale); case FX_LANG_zh_TW: - return GetLocaleFromBuffer(g_zhTW_Locale, sizeof(g_zhTW_Locale)); + return GetLocaleFromBuffer(g_zhTW_Locale); case FX_LANG_zh_HK: - return GetLocaleFromBuffer(g_zhHK_Locale, sizeof(g_zhHK_Locale)); + return GetLocaleFromBuffer(g_zhHK_Locale); case FX_LANG_ja_JP: - return GetLocaleFromBuffer(g_jaJP_Locale, sizeof(g_jaJP_Locale)); + return GetLocaleFromBuffer(g_jaJP_Locale); case FX_LANG_ko_KR: - return GetLocaleFromBuffer(g_koKR_Locale, sizeof(g_koKR_Locale)); + return GetLocaleFromBuffer(g_koKR_Locale); case FX_LANG_en_GB: - return GetLocaleFromBuffer(g_enGB_Locale, sizeof(g_enGB_Locale)); + return GetLocaleFromBuffer(g_enGB_Locale); case FX_LANG_es_LA: - return GetLocaleFromBuffer(g_esLA_Locale, sizeof(g_esLA_Locale)); + return GetLocaleFromBuffer(g_esLA_Locale); case FX_LANG_es_ES: - return GetLocaleFromBuffer(g_esES_Locale, sizeof(g_esES_Locale)); + return GetLocaleFromBuffer(g_esES_Locale); case FX_LANG_de_DE: - return GetLocaleFromBuffer(g_deDE_Loacale, sizeof(g_deDE_Loacale)); + return GetLocaleFromBuffer(g_deDE_Loacale); case FX_LANG_fr_FR: - return GetLocaleFromBuffer(g_frFR_Locale, sizeof(g_frFR_Locale)); + return GetLocaleFromBuffer(g_frFR_Locale); case FX_LANG_it_IT: - return GetLocaleFromBuffer(g_itIT_Locale, sizeof(g_itIT_Locale)); + return GetLocaleFromBuffer(g_itIT_Locale); case FX_LANG_pt_BR: - return GetLocaleFromBuffer(g_ptBR_Locale, sizeof(g_ptBR_Locale)); + return GetLocaleFromBuffer(g_ptBR_Locale); case FX_LANG_nl_NL: - return GetLocaleFromBuffer(g_nlNL_Locale, sizeof(g_nlNL_Locale)); + return GetLocaleFromBuffer(g_nlNL_Locale); case FX_LANG_ru_RU: - return GetLocaleFromBuffer(g_ruRU_Locale, sizeof(g_ruRU_Locale)); + return GetLocaleFromBuffer(g_ruRU_Locale); case FX_LANG_en_US: default: - return GetLocaleFromBuffer(g_enUS_Locale, sizeof(g_enUS_Locale)); + return GetLocaleFromBuffer(g_enUS_Locale); } } |