diff options
Diffstat (limited to 'core/fxcodec/gif')
-rw-r--r-- | core/fxcodec/gif/cfx_gifcontext.cpp | 4 | ||||
-rw-r--r-- | core/fxcodec/gif/cfx_gifcontext.h | 2 | ||||
-rw-r--r-- | core/fxcodec/gif/cfx_gifcontext_unittest.cpp | 96 |
3 files changed, 55 insertions, 47 deletions
diff --git a/core/fxcodec/gif/cfx_gifcontext.cpp b/core/fxcodec/gif/cfx_gifcontext.cpp index c1467ae233..076331f418 100644 --- a/core/fxcodec/gif/cfx_gifcontext.cpp +++ b/core/fxcodec/gif/cfx_gifcontext.cpp @@ -342,8 +342,8 @@ CFX_GifDecodeStatus CFX_GifContext::LoadFrame(int32_t frame_num) { return CFX_GifDecodeStatus::Error; } -void CFX_GifContext::SetInputBuffer(pdfium::span<uint8_t> src_buf) { - input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf); +void CFX_GifContext::SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory) { + input_buffer_ = std::move(codec_memory); } uint32_t CFX_GifContext::GetAvailInput() const { diff --git a/core/fxcodec/gif/cfx_gifcontext.h b/core/fxcodec/gif/cfx_gifcontext.h index c2828db6bb..4cf84a5ac6 100644 --- a/core/fxcodec/gif/cfx_gifcontext.h +++ b/core/fxcodec/gif/cfx_gifcontext.h @@ -41,7 +41,7 @@ class CFX_GifContext : public CodecModuleIface::Context { CFX_GifDecodeStatus ReadHeader(); CFX_GifDecodeStatus GetFrame(); CFX_GifDecodeStatus LoadFrame(int32_t frame_num); - void SetInputBuffer(pdfium::span<uint8_t> src_buf); + void SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory); uint32_t GetAvailInput() const; size_t GetFrameNum() const { return images_.size(); } diff --git a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp index b9805ef399..31cac45795 100644 --- a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp +++ b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp @@ -19,6 +19,9 @@ class CFX_GifContextForTest final : public CFX_GifContext { using CFX_GifContext::ReadLogicalScreenDescriptor; CFX_CodecMemory* InputBuffer() const { return input_buffer_.Get(); } + void SetTestInputBuffer(pdfium::span<uint8_t> input) { + SetInputBuffer(pdfium::MakeRetain<CFX_CodecMemory>(input)); + } }; TEST(CFX_GifContext, SetInputBuffer) { @@ -27,27 +30,27 @@ TEST(CFX_GifContext, SetInputBuffer) { // Context must not outlive its buffers. CFX_GifContextForTest context(nullptr, nullptr); - context.SetInputBuffer({nullptr, 0}); + context.SetTestInputBuffer({nullptr, 0}); EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer()); EXPECT_EQ(0u, context.InputBuffer()->GetSize()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({nullptr, 100}); + context.SetTestInputBuffer({nullptr, 100}); EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer()); EXPECT_EQ(100u, context.InputBuffer()->GetSize()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({buffer, 0}); + context.SetTestInputBuffer({buffer, 0}); EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer()); EXPECT_EQ(0u, context.InputBuffer()->GetSize()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({buffer, 3}); + context.SetTestInputBuffer({buffer, 3}); EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer()); EXPECT_EQ(3u, context.InputBuffer()->GetSize()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({buffer, 100}); + context.SetTestInputBuffer({buffer, 100}); EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer()); EXPECT_EQ(100u, context.InputBuffer()->GetSize()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); @@ -62,18 +65,18 @@ TEST(CFX_GifContext, ReadAllOrNone) { // Context must not outlive its buffers. CFX_GifContextForTest context(nullptr, nullptr); - context.SetInputBuffer({nullptr, 0}); + context.SetTestInputBuffer({nullptr, 0}); EXPECT_FALSE(context.ReadAllOrNone(nullptr, 0)); EXPECT_FALSE(context.ReadAllOrNone(nullptr, 10)); EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), 0)); EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), 10)); - context.SetInputBuffer({src_buffer, 0}); + context.SetTestInputBuffer({src_buffer, 0}); dest_buffer.resize(sizeof(src_buffer)); EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), sizeof(src_buffer))); - context.SetInputBuffer({src_buffer, 1}); + context.SetTestInputBuffer({src_buffer, 1}); EXPECT_FALSE(context.ReadAllOrNone(dest_buffer.data(), sizeof(src_buffer))); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); EXPECT_FALSE(context.ReadAllOrNone(nullptr, sizeof(src_buffer))); @@ -81,13 +84,13 @@ TEST(CFX_GifContext, ReadAllOrNone) { EXPECT_TRUE(context.ReadAllOrNone(dest_buffer.data(), 1)); EXPECT_EQ(src_buffer[0], dest_buffer[0]); - context.SetInputBuffer(src_buffer); + context.SetTestInputBuffer(src_buffer); EXPECT_FALSE(context.ReadAllOrNone(nullptr, sizeof(src_buffer))); EXPECT_TRUE(context.ReadAllOrNone(dest_buffer.data(), sizeof(src_buffer))); for (size_t i = 0; i < sizeof(src_buffer); i++) EXPECT_EQ(src_buffer[i], dest_buffer[i]); - context.SetInputBuffer(src_buffer); + context.SetTestInputBuffer(src_buffer); for (size_t i = 0; i < sizeof(src_buffer); i++) { EXPECT_TRUE(context.ReadAllOrNone(dest_buffer.data(), 1)); EXPECT_EQ(src_buffer[i], dest_buffer[0]); @@ -99,57 +102,57 @@ TEST(CFX_GifContext, ReadGifSignature) { CFX_GifContextForTest context(nullptr, nullptr); { uint8_t data[1]; - context.SetInputBuffer({data, 0}); + context.SetTestInputBuffer({data, 0}); EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadGifSignature()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Make sure testing the entire signature { uint8_t data[] = {'G', 'I', 'F'}; - context.SetInputBuffer(data); + context.SetTestInputBuffer(data); EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadGifSignature()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } { uint8_t data[] = {'N', 'O', 'T', 'G', 'I', 'F'}; - context.SetInputBuffer(data); + context.SetTestInputBuffer(data); EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature()); EXPECT_EQ(6u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Make sure not matching GIF8*a { uint8_t data[] = {'G', 'I', 'F', '8', '0', 'a'}; - context.SetInputBuffer(data); + context.SetTestInputBuffer(data); EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature()); EXPECT_EQ(6u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Make sure not matching GIF**a { uint8_t data[] = {'G', 'I', 'F', '9', '2', 'a'}; - context.SetInputBuffer(data); + context.SetTestInputBuffer(data); EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature()); EXPECT_EQ(6u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // One valid signature { uint8_t data[] = {'G', 'I', 'F', '8', '7', 'a'}; - context.SetInputBuffer(data); + context.SetTestInputBuffer(data); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadGifSignature()); EXPECT_EQ(6u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // The other valid signature { uint8_t data[] = {'G', 'I', 'F', '8', '9', 'a'}; - context.SetInputBuffer(data); + context.SetTestInputBuffer(data); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadGifSignature()); EXPECT_EQ(6u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } } @@ -157,16 +160,16 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) { CFX_GifContextForTest context(nullptr, nullptr); { uint8_t data[1]; - context.SetInputBuffer({data, 0}); + context.SetTestInputBuffer({data, 0}); EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadLogicalScreenDescriptor()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // LSD with all the values zero'd { uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)]; memset(&lsd, 0, sizeof(CFX_GifLocalScreenDescriptor)); - context.SetInputBuffer(lsd); + context.SetTestInputBuffer(lsd); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadLogicalScreenDescriptor()); @@ -177,13 +180,13 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) { EXPECT_EQ(0, context.height_); EXPECT_EQ(0u, context.bc_index_); EXPECT_EQ(0u, context.pixel_aspect_); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // LSD with no global palette { uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)] = {0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}; - context.SetInputBuffer(lsd); + context.SetTestInputBuffer(lsd); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadLogicalScreenDescriptor()); @@ -194,19 +197,19 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) { EXPECT_EQ(0x0F00, context.height_); EXPECT_EQ(0u, context.bc_index_); // bc_index_ is 0 if no global palette EXPECT_EQ(2u, context.pixel_aspect_); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // LSD with global palette bit set, but no global palette { uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)] = {0x0A, 0x00, 0x00, 0x0F, 0x80, 0x01, 0x02}; - context.SetInputBuffer(lsd); + context.SetTestInputBuffer(lsd); EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadLogicalScreenDescriptor()); EXPECT_EQ(0u, context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // LSD with global palette { @@ -215,7 +218,8 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) { uint8_t palette[4 * sizeof(CFX_GifPalette)]; } data = {{0x0A, 0x00, 0x00, 0x0F, 0xA9, 0x01, 0x02}, {0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1}}; - context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)}); + context.SetTestInputBuffer( + {reinterpret_cast<uint8_t*>(&data), sizeof(data)}); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadLogicalScreenDescriptor()); @@ -230,7 +234,7 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) { EXPECT_EQ(2, context.global_color_resolution_); EXPECT_EQ(0, memcmp(data.palette, context.global_palette_.data(), sizeof(data.palette))); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } } @@ -243,21 +247,22 @@ TEST(CFX_GifContext, ReadHeader) { uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)]; } data = {{'N', 'O', 'T', 'G', 'I', 'F'}, {0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}}; - context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)}); + context.SetTestInputBuffer( + {reinterpret_cast<uint8_t*>(&data), sizeof(data)}); EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadHeader()); EXPECT_EQ(sizeof(data.signature), context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Short after signature { uint8_t signature[] = {'G', 'I', 'F', '8', '7', 'a'}; - context.SetInputBuffer( + context.SetTestInputBuffer( {reinterpret_cast<uint8_t*>(&signature), sizeof(signature)}); EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadHeader()); EXPECT_EQ(sizeof(signature), context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Success without global palette { @@ -266,7 +271,8 @@ TEST(CFX_GifContext, ReadHeader) { uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)]; } data = {{'G', 'I', 'F', '8', '7', 'a'}, {0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}}; - context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)}); + context.SetTestInputBuffer( + {reinterpret_cast<uint8_t*>(&data), sizeof(data)}); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadHeader()); EXPECT_EQ(sizeof(data), context.InputBuffer()->GetPosition()); @@ -274,7 +280,7 @@ TEST(CFX_GifContext, ReadHeader) { EXPECT_EQ(0x0F00, context.height_); EXPECT_EQ(0u, context.bc_index_); // bc_index_ is 0 if no global palette EXPECT_EQ(2u, context.pixel_aspect_); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Missing Global Palette { @@ -283,11 +289,12 @@ TEST(CFX_GifContext, ReadHeader) { uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)]; } data = {{'G', 'I', 'F', '8', '7', 'a'}, {0x0A, 0x00, 0x00, 0x0F, 0x80, 0x01, 0x02}}; - context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)}); + context.SetTestInputBuffer( + {reinterpret_cast<uint8_t*>(&data), sizeof(data)}); EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadHeader()); EXPECT_EQ(sizeof(data.signature), context.InputBuffer()->GetPosition()); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } // Success with global palette { @@ -298,7 +305,8 @@ TEST(CFX_GifContext, ReadHeader) { } data = {{'G', 'I', 'F', '8', '7', 'a'}, {0x0A, 0x00, 0x00, 0x0F, 0xA9, 0x01, 0x02}, {0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1}}; - context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)}); + context.SetTestInputBuffer( + {reinterpret_cast<uint8_t*>(&data), sizeof(data)}); EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadHeader()); EXPECT_EQ(sizeof(data), context.InputBuffer()->GetPosition()); @@ -311,6 +319,6 @@ TEST(CFX_GifContext, ReadHeader) { EXPECT_EQ(2, context.global_color_resolution_); EXPECT_EQ(0, memcmp(data.palette, context.global_palette_.data(), sizeof(data.palette))); - context.SetInputBuffer({}); + context.SetTestInputBuffer({}); } } |