diff options
author | Lei Zhang <thestig@chromium.org> | 2018-09-11 07:59:18 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-09-11 07:59:18 +0000 |
commit | bb06ae5ad0b6389490befc6831517ab383e94031 (patch) | |
tree | 97e9e2367db537f6a4f459481d77103973450b3c /core/fpdfapi/parser | |
parent | c2f404f993f13d303f9e47d2f97aff727becac7d (diff) | |
download | pdfium-bb06ae5ad0b6389490befc6831517ab383e94031.tar.xz |
Make flate decode functions' buffer out parameter unique_ptrs.
Change-Id: Idb14846e87a8287dd911b0a2f7a32146e86c2af7
Reviewed-on: https://pdfium-review.googlesource.com/41853
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.cpp | 12 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp | 5 |
3 files changed, 12 insertions, 9 deletions
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 9041666c07..eafb8ee8a3 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -320,7 +320,7 @@ uint32_t FlateOrLZWDecode(bool bLZW, pdfium::span<const uint8_t> src_span, const CPDF_Dictionary* pParams, uint32_t estimated_size, - uint8_t** dest_buf, + std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, uint32_t* dest_size) { int predictor = 0; int Colors = 0; @@ -389,11 +389,15 @@ bool PDF_DataDecode(pdfium::span<const uint8_t> src_span, *pImageParams = pParam; return true; } + std::unique_ptr<uint8_t, FxFreeDeleter> result; offset = FlateOrLZWDecode(false, last_span, pParam, estimated_size, - &new_buf, &new_size); + &result, &new_size); + new_buf = result.release(); } else if (decoder == "LZWDecode" || decoder == "LZW") { + std::unique_ptr<uint8_t, FxFreeDeleter> result; offset = FlateOrLZWDecode(true, last_span, pParam, estimated_size, - &new_buf, &new_size); + &result, &new_size); + new_buf = result.release(); } else if (decoder == "ASCII85Decode" || decoder == "A85") { std::unique_ptr<uint8_t, FxFreeDeleter> result; offset = A85Decode(last_span, &result, &new_size); @@ -578,7 +582,7 @@ bool FlateEncode(pdfium::span<const uint8_t> src_span, } uint32_t FlateDecode(pdfium::span<const uint8_t> src_span, - uint8_t** dest_buf, + std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, uint32_t* dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); return pEncoders->GetFlateModule()->FlateOrLZWDecode( diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h index 0032b97423..e4fdce1037 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.h +++ b/core/fpdfapi/parser/fpdf_parser_decode.h @@ -44,7 +44,7 @@ bool FlateEncode(pdfium::span<const uint8_t> src_span, uint32_t* dest_size); uint32_t FlateDecode(pdfium::span<const uint8_t> src_span, - uint8_t** dest_buf, + std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, uint32_t* dest_size); uint32_t RunLengthDecode(pdfium::span<const uint8_t> src_span, @@ -63,7 +63,7 @@ uint32_t FlateOrLZWDecode(bool bLZW, pdfium::span<const uint8_t> src_span, const CPDF_Dictionary* pParams, uint32_t estimated_size, - uint8_t** dest_buf, + std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf, uint32_t* dest_size); bool PDF_DataDecode(pdfium::span<const uint8_t> src_span, diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp index d7256f0da5..94776e17ea 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp @@ -74,7 +74,7 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) { for (size_t i = 0; i < FX_ArraySize(flate_decode_cases); ++i) { const pdfium::DecodeTestData& data = flate_decode_cases[i]; - unsigned char* buf = nullptr; + std::unique_ptr<uint8_t, FxFreeDeleter> buf; uint32_t buf_size; EXPECT_EQ(data.processed_size, FlateDecode({data.input, data.input_size}, &buf, &buf_size)) @@ -83,9 +83,8 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateDecode) { EXPECT_EQ(data.expected_size, buf_size) << " for case " << i; if (data.expected_size != buf_size) continue; - EXPECT_EQ(0, memcmp(data.expected, buf, data.expected_size)) + EXPECT_EQ(0, memcmp(data.expected, buf.get(), data.expected_size)) << " for case " << i; - FX_Free(buf); } } |