diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcodec/codec/ccodec_basicmodule.h | 8 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec.cpp | 73 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_a85_unittest.cpp | 41 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_rle_unittest.cpp | 66 | ||||
-rw-r--r-- | core/fxge/win32/cfx_psrenderer.cpp | 6 |
5 files changed, 87 insertions, 107 deletions
diff --git a/core/fxcodec/codec/ccodec_basicmodule.h b/core/fxcodec/codec/ccodec_basicmodule.h index b07efd884f..2ad374037f 100644 --- a/core/fxcodec/codec/ccodec_basicmodule.h +++ b/core/fxcodec/codec/ccodec_basicmodule.h @@ -22,12 +22,12 @@ class CCodec_BasicModule { int height, int nComps, int bpc); - bool RunLengthEncode(const uint8_t* src_buf, - uint32_t src_size, + + bool RunLengthEncode(pdfium::span<const uint8_t> src_buf, uint8_t** dest_buf, uint32_t* dest_size); - bool A85Encode(const uint8_t* src_buf, - uint32_t src_size, + + bool A85Encode(pdfium::span<const uint8_t> src_buf, uint8_t** dest_buf, uint32_t* dest_size); }; diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp index 1a21c92415..efae53908e 100644 --- a/core/fxcodec/codec/fx_codec.cpp +++ b/core/fxcodec/codec/fx_codec.cpp @@ -1357,19 +1357,18 @@ CCodec_ModuleMgr::CCodec_ModuleMgr() CCodec_ModuleMgr::~CCodec_ModuleMgr() {} -bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, - uint32_t src_size, +bool CCodec_BasicModule::RunLengthEncode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { // Check inputs - if (!src_buf || !dest_buf || !dest_size || src_size == 0) + if (src_span.empty() || !dest_buf || !dest_size) return false; // Edge case - if (src_size == 1) { + if (src_span.size() == 1) { *dest_buf = FX_Alloc(uint8_t, 3); (*dest_buf)[0] = 0; - (*dest_buf)[1] = src_buf[0]; + (*dest_buf)[1] = src_span[0]; (*dest_buf)[2] = 128; *dest_size = 3; return true; @@ -1378,25 +1377,29 @@ bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, // Worst case: 1 nonmatch, 2 match, 1 nonmatch, 2 match, etc. This becomes // 4 output chars for every 3 input, plus up to 4 more for the 1-2 chars // rounded off plus the terminating character. - uint32_t est_size = 4 * ((src_size + 2) / 3) + 1; - *dest_buf = FX_Alloc(uint8_t, est_size); + FX_SAFE_SIZE_T estimated_size = src_span.size(); + estimated_size += 2; + estimated_size /= 3; + estimated_size *= 4; + estimated_size += 1; + *dest_buf = FX_Alloc(uint8_t, estimated_size.ValueOrDie()); // Set up pointers. uint8_t* out = *dest_buf; uint32_t run_start = 0; uint32_t run_end = 1; - uint8_t x = src_buf[run_start]; - uint8_t y = src_buf[run_end]; - while (run_end < src_size) { - uint32_t max_len = std::min((uint32_t)128, src_size - run_start); + uint8_t x = src_span[run_start]; + uint8_t y = src_span[run_end]; + while (run_end < src_span.size()) { + size_t max_len = std::min<size_t>(128, src_span.size() - run_start); while (x == y && (run_end - run_start < max_len - 1)) - y = src_buf[++run_end]; + y = src_span[++run_end]; // Reached end with matched run. Update variables to expected values. if (x == y) { run_end++; - if (run_end < src_size) - y = src_buf[run_end]; + if (run_end < src_span.size()) + y = src_span[run_end]; } if (run_end - run_start > 1) { // Matched run but not at end of input. out[0] = 257 - (run_end - run_start); @@ -1404,8 +1407,8 @@ bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, x = y; run_start = run_end; run_end++; - if (run_end < src_size) - y = src_buf[run_end]; + if (run_end < src_span.size()) + y = src_span[run_end]; out += 2; continue; } @@ -1414,20 +1417,20 @@ bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, out[run_end - run_start] = x; x = y; run_end++; - if (run_end == src_size) { + if (run_end == src_span.size()) { if (run_end <= run_start + max_len) { out[run_end - run_start] = x; run_end++; } break; } - y = src_buf[run_end]; + y = src_span[run_end]; } out[0] = run_end - run_start - 2; out += run_end - run_start; run_start = run_end - 1; } - if (run_start < src_size) { // 1 leftover character + if (run_start < src_span.size()) { // 1 leftover character out[0] = 0; out[1] = x; out += 2; @@ -1437,15 +1440,14 @@ bool CCodec_BasicModule::RunLengthEncode(const uint8_t* src_buf, return true; } -bool CCodec_BasicModule::A85Encode(const uint8_t* src_buf, - uint32_t src_size, +bool CCodec_BasicModule::A85Encode(pdfium::span<const uint8_t> src_span, uint8_t** dest_buf, uint32_t* dest_size) { // Check inputs. - if (!src_buf || !dest_buf || !dest_size) + if (!dest_buf || !dest_size) return false; - if (src_size == 0) { + if (src_span.empty()) { *dest_size = 0; return false; } @@ -1453,18 +1455,23 @@ bool CCodec_BasicModule::A85Encode(const uint8_t* src_buf, // Worst case: 5 output for each 4 input (plus up to 4 from leftover), plus // 2 character new lines each 75 output chars plus 2 termination chars. May // have fewer if there are special "z" chars. - uint32_t est_size = 5 * (src_size / 4) + 4 + src_size / 30 + 2; - *dest_buf = FX_Alloc(uint8_t, est_size); + FX_SAFE_SIZE_T estimated_size = src_span.size(); + estimated_size /= 4; + estimated_size *= 5; + estimated_size += 4; + estimated_size += src_span.size() / 30; + estimated_size += 2; + *dest_buf = FX_Alloc(uint8_t, estimated_size.ValueOrDie()); // Set up pointers. uint8_t* out = *dest_buf; uint32_t pos = 0; uint32_t line_length = 0; - while (src_size >= 4 && pos < src_size - 3) { - uint32_t val = ((uint32_t)(src_buf[pos]) << 24) + - ((uint32_t)(src_buf[pos + 1]) << 16) + - ((uint32_t)(src_buf[pos + 2]) << 8) + - (uint32_t)(src_buf[pos + 3]); + while (src_span.size() >= 4 && pos < src_span.size() - 3) { + uint32_t val = ((uint32_t)(src_span[pos]) << 24) + + ((uint32_t)(src_span[pos + 1]) << 16) + + ((uint32_t)(src_span[pos + 2]) << 8) + + (uint32_t)(src_span[pos + 3]); pos += 4; if (val == 0) { // All zero special case *out = 'z'; @@ -1484,11 +1491,11 @@ bool CCodec_BasicModule::A85Encode(const uint8_t* src_buf, line_length = 0; } } - if (pos < src_size) { // Leftover bytes + if (pos < src_span.size()) { // Leftover bytes uint32_t val = 0; int count = 0; - while (pos < src_size) { - val += (uint32_t)(src_buf[pos]) << (8 * (3 - count)); + while (pos < src_span.size()) { + val += (uint32_t)(src_span[pos]) << (8 * (3 - count)); count++; pos++; } diff --git a/core/fxcodec/codec/fx_codec_a85_unittest.cpp b/core/fxcodec/codec/fx_codec_a85_unittest.cpp index 5e40548bf2..e0b6964f53 100644 --- a/core/fxcodec/codec/fx_codec_a85_unittest.cpp +++ b/core/fxcodec/codec/fx_codec_a85_unittest.cpp @@ -13,17 +13,15 @@ TEST(fxcodec, A85TestBadInputs) { const uint8_t src_buf[] = {1, 2, 3, 4}; uint8_t* dest_buf = nullptr; - uint32_t src_size = 4; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); // Error codes, not segvs, should callers pass us a nullptr pointer. - EXPECT_FALSE(pEncoders->A85Encode(src_buf, src_size, &dest_buf, nullptr)); - EXPECT_FALSE(pEncoders->A85Encode(src_buf, src_size, nullptr, &dest_size)); - EXPECT_FALSE(pEncoders->A85Encode(src_buf, 0, &dest_buf, &dest_size)); - EXPECT_FALSE(pEncoders->A85Encode(nullptr, src_size, &dest_buf, &dest_size)); + EXPECT_FALSE(pEncoders->A85Encode(src_buf, &dest_buf, nullptr)); + EXPECT_FALSE(pEncoders->A85Encode(src_buf, nullptr, &dest_size)); + EXPECT_FALSE(pEncoders->A85Encode({}, &dest_buf, &dest_size)); } // No leftover bytes, just translate 2 sets of symbols. @@ -31,14 +29,13 @@ TEST(fxcodec, A85TestBasic) { // Make sure really big values don't break. const uint8_t src_buf[] = {1, 2, 3, 4, 255, 255, 255, 255}; uint8_t* dest_buf = nullptr; - uint32_t src_size = 8; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); // Should succeed. - EXPECT_TRUE(pEncoders->A85Encode(src_buf, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf, &dest_buf, &dest_size)); // Should have 5 chars for each set of 4 and 2 terminators. ASSERT_EQ(12u, dest_size); @@ -56,15 +53,13 @@ TEST(fxcodec, A85TestLeftoverBytes) { // 1 Leftover Byte: const uint8_t src_buf_1leftover[] = {1, 2, 3, 4, 255}; uint8_t* dest_buf = nullptr; - uint32_t src_size = 5; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); // Should succeed - EXPECT_TRUE( - pEncoders->A85Encode(src_buf_1leftover, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf_1leftover, &dest_buf, &dest_size)); ASSERT_EQ(9u, dest_size); // 5 chars for first symbol + 2 + 2 terminators. uint8_t expected_out_1leftover[] = {33, 60, 78, 63, 43, 114, 114, 126, 62}; @@ -74,13 +69,11 @@ TEST(fxcodec, A85TestLeftoverBytes) { FX_Free(dest_buf); // 2 Leftover bytes: - src_size++; + const uint8_t src_buf_2leftover[] = {1, 2, 3, 4, 255, 254}; dest_buf = nullptr; dest_size = 0; - const uint8_t src_buf_2leftover[] = {1, 2, 3, 4, 255, 254}; // Should succeed - EXPECT_TRUE( - pEncoders->A85Encode(src_buf_2leftover, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf_2leftover, &dest_buf, &dest_size)); ASSERT_EQ(10u, dest_size); // 5 chars for first symbol + 3 + 2 terminators. const uint8_t expected_out_2leftover[] = {33, 60, 78, 63, 43, 115, 56, 68, 126, 62}; @@ -91,13 +84,11 @@ TEST(fxcodec, A85TestLeftoverBytes) { FX_Free(dest_buf); // 3 Leftover bytes: - src_size++; + const uint8_t src_buf_3leftover[] = {1, 2, 3, 4, 255, 254, 253}; dest_buf = nullptr; dest_size = 0; - const uint8_t src_buf_3leftover[] = {1, 2, 3, 4, 255, 254, 253}; // Should succeed - EXPECT_TRUE( - pEncoders->A85Encode(src_buf_3leftover, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf_3leftover, &dest_buf, &dest_size)); ASSERT_EQ(11u, dest_size); // 5 chars for first symbol + 4 + 2 terminators. const uint8_t expected_out_3leftover[] = {33, 60, 78, 63, 43, 115, 56, 77, 114, 126, 62}; @@ -113,14 +104,13 @@ TEST(fxcodec, A85TestZeros) { // Make sure really big values don't break. const uint8_t src_buf[] = {1, 2, 3, 4, 0, 0, 0, 0}; uint8_t* dest_buf = nullptr; - uint32_t src_size = 8; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); // Should succeed. - EXPECT_TRUE(pEncoders->A85Encode(src_buf, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf, &dest_buf, &dest_size)); // Should have 5 chars for first set of 4 + 1 for z + 2 terminators. ASSERT_EQ(8u, dest_size); @@ -132,12 +122,12 @@ TEST(fxcodec, A85TestZeros) { FX_Free(dest_buf); // Should also work if it is at the start: + const uint8_t src_buf_2[] = {0, 0, 0, 0, 1, 2, 3, 4}; dest_buf = nullptr; dest_size = 0; - const uint8_t src_buf_2[] = {0, 0, 0, 0, 1, 2, 3, 4}; // Should succeed. - EXPECT_TRUE(pEncoders->A85Encode(src_buf_2, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf_2, &dest_buf, &dest_size)); // Should have 5 chars for set of 4 + 1 for z + 2 terminators. ASSERT_EQ(8u, dest_size); @@ -149,12 +139,12 @@ TEST(fxcodec, A85TestZeros) { FX_Free(dest_buf); // Try with 2 leftover zero bytes. Make sure we don't get a "z". - src_size = 6; // Cut off the last 2 zeros. + const uint8_t src_buf_3[] = {1, 2, 3, 4, 0, 0}; dest_buf = nullptr; dest_size = 0; // Should succeed. - EXPECT_TRUE(pEncoders->A85Encode(src_buf, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf_3, &dest_buf, &dest_size)); // Should have 5 chars for set of 4 + 3 for last 2 + 2 terminators. ASSERT_EQ(10u, dest_size); @@ -186,14 +176,13 @@ TEST(fxcodec, A85TestLineBreaks) { src_buf[k + 3] = 4; } uint8_t* dest_buf = nullptr; - uint32_t src_size = 131; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); // Should succeed. - EXPECT_TRUE(pEncoders->A85Encode(src_buf, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->A85Encode(src_buf, &dest_buf, &dest_size)); // Should have 75 chars in the first row plus 2 char return, // 76 chars in the second row plus 2 char return, diff --git a/core/fxcodec/codec/fx_codec_rle_unittest.cpp b/core/fxcodec/codec/fx_codec_rle_unittest.cpp index 47067cb030..62ea4e7a76 100644 --- a/core/fxcodec/codec/fx_codec_rle_unittest.cpp +++ b/core/fxcodec/codec/fx_codec_rle_unittest.cpp @@ -14,34 +14,27 @@ TEST(fxcodec, RLETestBadInputs) { const uint8_t src_buf[] = {1}; uint8_t* dest_buf = nullptr; - uint32_t src_size = 4; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); // Error codes, not segvs, should callers pass us a nullptr pointer. - EXPECT_FALSE( - pEncoders->RunLengthEncode(src_buf, src_size, &dest_buf, nullptr)); - EXPECT_FALSE( - pEncoders->RunLengthEncode(src_buf, src_size, nullptr, &dest_size)); - EXPECT_FALSE(pEncoders->RunLengthEncode(src_buf, 0, &dest_buf, &dest_size)); - EXPECT_FALSE( - pEncoders->RunLengthEncode(nullptr, src_size, &dest_buf, &dest_size)); + EXPECT_FALSE(pEncoders->RunLengthEncode(src_buf, &dest_buf, nullptr)); + EXPECT_FALSE(pEncoders->RunLengthEncode(src_buf, nullptr, &dest_size)); + EXPECT_FALSE(pEncoders->RunLengthEncode({}, &dest_buf, &dest_size)); } // Check length 1 input works. Check terminating character is applied. TEST(fxcodec, RLETestShortInput) { const uint8_t src_buf[] = {1}; uint8_t* dest_buf = nullptr; - uint32_t src_size = 1; uint32_t dest_size = 0; CCodec_BasicModule* pEncoders = CCodec_ModuleMgr().GetBasicModule(); EXPECT_TRUE(pEncoders); - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf, &dest_buf, &dest_size)); ASSERT_EQ(3u, dest_size); EXPECT_EQ(0, dest_buf[0]); EXPECT_EQ(1, dest_buf[1]); @@ -62,7 +55,6 @@ TEST(fxcodec, RLETestNormalInputs) { // Non-match, match const uint8_t src_buf_3[] = {1, 2, 3, 4, 5, 3, 3, 3, 3, 3}; - uint32_t src_size = 10; uint32_t dest_size = 0; uint8_t* dest_buf = nullptr; @@ -70,13 +62,12 @@ TEST(fxcodec, RLETestNormalInputs) { EXPECT_TRUE(pEncoders); // Case 1: - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_1, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_1, &dest_buf, &dest_size)); uint8_t* decoded_buf = nullptr; uint32_t decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_1), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); @@ -84,13 +75,12 @@ TEST(fxcodec, RLETestNormalInputs) { // Case 2: dest_buf = nullptr; dest_size = 0; - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_2, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_2, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_2), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); @@ -98,13 +88,12 @@ TEST(fxcodec, RLETestNormalInputs) { // Case 3: dest_buf = nullptr; dest_size = 0; - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_3, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_3, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_3), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); @@ -131,7 +120,6 @@ TEST(fxcodec, RLETestFullLengthInputs) { for (uint16_t i = 0; i < 260; i++) src_buf_4[i] = (uint8_t)(i); - uint32_t src_size = 260; uint32_t dest_size = 0; uint8_t* dest_buf = nullptr; @@ -139,13 +127,12 @@ TEST(fxcodec, RLETestFullLengthInputs) { EXPECT_TRUE(pEncoders); // Case 1: - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_1, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_1, &dest_buf, &dest_size)); uint8_t* decoded_buf = nullptr; uint32_t decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_1), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_1[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); @@ -153,13 +140,12 @@ TEST(fxcodec, RLETestFullLengthInputs) { // Case 2: dest_buf = nullptr; dest_size = 0; - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_2, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_2, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_2), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_2[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); @@ -167,13 +153,12 @@ TEST(fxcodec, RLETestFullLengthInputs) { // Case 3: dest_buf = nullptr; dest_size = 0; - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_3, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_3, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_3), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_3[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); @@ -181,13 +166,12 @@ TEST(fxcodec, RLETestFullLengthInputs) { // Case 4: dest_buf = nullptr; dest_size = 0; - EXPECT_TRUE( - pEncoders->RunLengthEncode(src_buf_4, src_size, &dest_buf, &dest_size)); + EXPECT_TRUE(pEncoders->RunLengthEncode(src_buf_4, &dest_buf, &dest_size)); decoded_buf = nullptr; decoded_size = 0; RunLengthDecode({dest_buf, dest_size}, &decoded_buf, &decoded_size); - ASSERT_EQ(src_size, decoded_size); - for (uint32_t i = 0; i < src_size; i++) + ASSERT_EQ(sizeof(src_buf_4), decoded_size); + for (uint32_t i = 0; i < decoded_size; i++) EXPECT_EQ(src_buf_4[i], decoded_buf[i]) << " at " << i; FX_Free(dest_buf); FX_Free(decoded_buf); diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index f5970a3ad1..dbc212123c 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -64,7 +64,7 @@ void PSCompressData(int PSLevel, *filter = "/FlateDecode filter "; } } else { - if (pEncoders->GetBasicModule()->RunLengthEncode(src_buf, src_size, + if (pEncoders->GetBasicModule()->RunLengthEncode({src_buf, src_size}, &dest_buf, &dest_size)) { *filter = "/RunLengthDecode filter "; } @@ -689,8 +689,8 @@ void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) { uint8_t* dest_buf; uint32_t dest_size; CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); - if (pEncoders->GetBasicModule()->A85Encode(data, len, &dest_buf, - &dest_size)) { + if (pEncoders->GetBasicModule()->A85Encode({data, static_cast<size_t>(len)}, + &dest_buf, &dest_size)) { m_pStream->WriteBlock(dest_buf, dest_size); FX_Free(dest_buf); } else { |