summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/fpdf_parser')
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp41
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp12
-rw-r--r--core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h23
3 files changed, 36 insertions, 40 deletions
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 7c489a35dc..40ba362ad6 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -532,45 +532,40 @@ CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) {
result.AppendChar('(');
for (int i = 0; i < srclen; i++) {
uint8_t ch = src[i];
- if (ch == ')' || ch == '\\' || ch == '(') {
- result.AppendChar('\\');
- } else if (ch == 0x0a) {
+ if (ch == 0x0a) {
result << "\\n";
continue;
- } else if (ch == 0x0d) {
+ }
+ if (ch == 0x0d) {
result << "\\r";
continue;
}
+ if (ch == ')' || ch == '\\' || ch == '(')
+ result.AppendChar('\\');
result.AppendChar(ch);
}
result.AppendChar(')');
return result.MakeString();
}
-void FlateEncode(const uint8_t* src_buf,
+bool FlateEncode(const uint8_t* src_buf,
uint32_t src_size,
- uint8_t*& dest_buf,
- uint32_t& dest_size) {
+ uint8_t** dest_buf,
+ uint32_t* dest_size) {
CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
- if (pEncoders) {
- pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size);
- }
+ return pEncoders &&
+ pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf,
+ dest_size);
}
-void FlateEncode(const uint8_t* src_buf,
- uint32_t src_size,
- int predictor,
- int Colors,
- int BitsPerComponent,
- int Columns,
- uint8_t*& dest_buf,
- uint32_t& dest_size) {
+bool PngEncode(const uint8_t* src_buf,
+ uint32_t src_size,
+ uint8_t** dest_buf,
+ uint32_t* dest_size) {
CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
- if (pEncoders) {
- pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors,
- BitsPerComponent, Columns, dest_buf,
- dest_size);
- }
+ return pEncoders &&
+ pEncoders->GetFlateModule()->PngEncode(src_buf, src_size, dest_buf,
+ dest_size);
}
uint32_t FlateDecode(const uint8_t* src_buf,
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
index 308c9f11c9..e9ca958411 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp
@@ -38,14 +38,14 @@ TEST_F(FPDFParserDecodeEmbeddertest, FlateEncode) {
for (size_t i = 0; i < FX_ArraySize(flate_encode_cases); ++i) {
const pdfium::StrFuncTestData& data = flate_encode_cases[i];
- unsigned char* result;
- unsigned int result_size;
- FlateEncode(data.input, data.input_size, result, result_size);
- ASSERT_TRUE(result);
+ unsigned char* buf = nullptr;
+ unsigned int buf_size;
+ EXPECT_TRUE(FlateEncode(data.input, data.input_size, &buf, &buf_size));
+ ASSERT_TRUE(buf);
EXPECT_EQ(std::string((const char*)data.expected, data.expected_size),
- std::string((const char*)result, result_size))
+ std::string((const char*)buf, buf_size))
<< " for case " << i;
- FX_Free(result);
+ FX_Free(buf);
}
}
diff --git a/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h b/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h
index 1f1095b396..5ae4011c76 100644
--- a/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h
+++ b/core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h
@@ -24,18 +24,19 @@ CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr);
CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len = -1);
CFX_ByteString PDF_EncodeText(const CFX_WideString& str);
-void FlateEncode(const uint8_t* src_buf,
+bool FlateEncode(const uint8_t* src_buf,
uint32_t src_size,
- uint8_t*& dest_buf,
- uint32_t& dest_size);
-void FlateEncode(const uint8_t* src_buf,
- uint32_t src_size,
- int predictor,
- int Colors,
- int BitsPerComponent,
- int Columns,
- uint8_t*& dest_buf,
- uint32_t& dest_size);
+ uint8_t** dest_buf,
+ uint32_t* dest_size);
+
+// This used to have more parameters like the predictor and bpc, but there was
+// only one caller, so the interface has been simplified, the values are hard
+// coded, and dead code has been removed.
+bool PngEncode(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,