42TEST(ParserDecodeTest, ValidateDecoderPipeline) {
45 auto decoders = pdfium::MakeRetain<CPDF_Array>();
46 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
50 auto decoders = pdfium::MakeRetain<CPDF_Array>();
51 decoders->AppendNew<CPDF_Name>(
"FlateEncode");
52 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
56 auto decoders = pdfium::MakeRetain<CPDF_Array>();
57 decoders->AppendNew<CPDF_Name>(
"FooBar");
58 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
62 auto decoders = pdfium::MakeRetain<CPDF_Array>();
63 decoders->AppendNew<CPDF_Name>(
"AHx");
64 decoders->AppendNew<CPDF_Name>(
"LZWDecode");
65 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
69 auto decoders = pdfium::MakeRetain<CPDF_Array>();
70 decoders->AppendNew<CPDF_Name>(
"ASCII85Decode");
71 decoders->AppendNew<CPDF_Name>(
"ASCII85Decode");
72 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
76 auto decoders = pdfium::MakeRetain<CPDF_Array>();
77 decoders->AppendNew<CPDF_Name>(
"ASCII85Decode");
78 decoders->AppendNew<CPDF_Name>(
"A85");
79 decoders->AppendNew<CPDF_Name>(
"RunLengthDecode");
80 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
81 decoders->AppendNew<CPDF_Name>(
"RL");
82 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
86 auto decoders = pdfium::MakeRetain<CPDF_Array>();
87 decoders->AppendNew<CPDF_Name>(
"RunLengthDecode");
88 decoders->AppendNew<CPDF_Name>(
"ASCII85Decode");
89 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
90 decoders->AppendNew<CPDF_Name>(
"LZW");
91 decoders->AppendNew<CPDF_Name>(
"DCTDecode");
92 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
96 auto decoders = pdfium::MakeRetain<CPDF_Array>();
97 decoders->AppendNew<CPDF_String>(
"FlateEncode",
false);
98 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
102 auto decoders = pdfium::MakeRetain<CPDF_Array>();
103 decoders->AppendNew<CPDF_Name>(
"DCTDecode");
104 decoders->AppendNew<CPDF_Name>(
"CCITTFaxDecode");
105 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
109 auto decoders = pdfium::MakeRetain<CPDF_Array>();
110 decoders->AppendNew<CPDF_Name>(
"DCTDecode");
111 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
112 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
116 auto decoders = pdfium::MakeRetain<CPDF_Array>();
117 decoders->AppendNew<CPDF_String>(
"AHx",
false);
118 decoders->AppendNew<CPDF_Name>(
"LZWDecode");
119 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
123 auto decoders = pdfium::MakeRetain<CPDF_Array>();
124 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
125 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
126 decoders->AppendNew<CPDF_Name>(
"DCTDecode");
127 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
128 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
129 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
133 auto decoders = pdfium::MakeRetain<CPDF_Array>();
134 decoders->AppendNew<CPDF_Name>(
"ASCII85Decode");
135 decoders->AppendNew<CPDF_Name>(
"A85");
136 decoders->AppendNew<CPDF_Name>(
"RunLengthDecode");
137 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
138 decoders->AppendNew<CPDF_String>(
"RL",
false);
139 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
147 auto decoder = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"FlateDecode");
148 uint32_t decoder_number =
151 auto decoders = pdfium::MakeRetain<CPDF_Array>();
152 decoders->AppendNew<CPDF_Reference>(&objects_holder, decoder_number);
153 decoders->AppendNew<CPDF_Name>(
"LZW");
154 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
160 auto decoder = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"LZW");
161 uint32_t decoder_number =
164 auto decoders = pdfium::MakeRetain<CPDF_Array>();
165 decoders->AppendNew<CPDF_Name>(
"RunLengthDecode");
166 decoders->AppendNew<CPDF_Name>(
"ASCII85Decode");
167 decoders->AppendNew<CPDF_Name>(
"FlateDecode");
168 decoders->AppendNew<CPDF_Reference>(&objects_holder, decoder_number);
169 decoders->AppendNew<CPDF_Name>(
"DCTDecode");
170 EXPECT_TRUE(ValidateDecoderPipeline(decoders.Get()));
176 pdfium::MakeRetain<CPDF_String>(
nullptr,
"FlateDecode",
false);
177 uint32_t decoder_number =
180 auto decoders = pdfium::MakeRetain<CPDF_Array>();
181 decoders->AppendNew<CPDF_Reference>(&objects_holder, decoder_number);
182 decoders->AppendNew<CPDF_Name>(
"LZW");
183 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
188 auto decoder = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"DCTDecode");
189 uint32_t decoder_number =
192 auto decoders = pdfium::MakeRetain<CPDF_Array>();
193 decoders->AppendNew<CPDF_Reference>(&objects_holder, decoder_number);
194 decoders->AppendNew<CPDF_Name>(
"LZW");
195 EXPECT_FALSE(ValidateDecoderPipeline(decoders.Get()));
200TEST(ParserDecodeTest, GetDecoderArray) {
203 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
204 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
205 ASSERT_TRUE(decoder_array.has_value());
206 EXPECT_TRUE(decoder_array.value().empty());
210 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
211 dict->SetNewFor<CPDF_String>(
"Filter",
"RL",
false);
212 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
213 EXPECT_FALSE(decoder_array.has_value());
217 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
218 dict->SetNewFor<CPDF_Name>(
"Filter",
"RL");
219 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
220 ASSERT_TRUE(decoder_array.has_value());
221 ASSERT_EQ(1u, decoder_array.value().size());
222 EXPECT_EQ(
"RL", decoder_array.value()[0].first);
226 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
227 dict->SetNewFor<CPDF_Array>(
"Filter");
228 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
229 ASSERT_TRUE(decoder_array.has_value());
230 EXPECT_TRUE(decoder_array.value().empty());
234 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
235 auto filter_array = dict->SetNewFor<CPDF_Array>(
"Filter");
236 filter_array->AppendNew<CPDF_Name>(
"FooBar");
237 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
238 ASSERT_TRUE(decoder_array.has_value());
239 ASSERT_EQ(1u, decoder_array.value().size());
240 EXPECT_EQ(
"FooBar", decoder_array.value()[0].first);
244 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
245 auto filter_array = dict->SetNewFor<CPDF_Array>(
"Filter");
246 filter_array->AppendNew<CPDF_Name>(
"AHx");
247 filter_array->AppendNew<CPDF_Name>(
"LZWDecode");
248 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
249 ASSERT_TRUE(decoder_array.has_value());
250 ASSERT_EQ(2u, decoder_array.value().size());
251 EXPECT_EQ(
"AHx", decoder_array.value()[0].first);
252 EXPECT_EQ(
"LZWDecode", decoder_array.value()[1].first);
256 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
257 auto invalid_filter_array = dict->SetNewFor<CPDF_Array>(
"Filter");
258 invalid_filter_array->AppendNew<CPDF_Name>(
"DCTDecode");
259 invalid_filter_array->AppendNew<CPDF_Name>(
"CCITTFaxDecode");
260 absl::optional<DecoderArray> decoder_array = GetDecoderArray(dict);
261 EXPECT_FALSE(decoder_array.has_value());
265TEST(ParserDecodeTest, A85Decode) {
266 const pdfium::DecodeTestData kTestData[] = {
284 for (
const auto& test_case : kTestData) {
285 std::unique_ptr<uint8_t, FxFreeDeleter> result;
286 uint32_t result_size = 0;
287 EXPECT_EQ(test_case.processed_size,
288 A85Decode({test_case.input, test_case.input_size}, &result,
290 <<
"for case " << test_case.input;
291 ASSERT_EQ(test_case.expected_size, result_size);
292 const uint8_t* result_ptr = result.get();
293 for (size_t j = 0; j < result_size; ++j) {
294 EXPECT_EQ(test_case.expected[j], result_ptr[j])
295 <<
"for case " << test_case.input <<
" char " << j;
300TEST(ParserDecodeTest, HexDecode) {
301 const pdfium::DecodeTestData kTestData[] = {
319 for (
const auto& test_case : kTestData) {
320 std::unique_ptr<uint8_t, FxFreeDeleter> result;
321 uint32_t result_size = 0;
322 EXPECT_EQ(test_case.processed_size,
323 HexDecode({test_case.input, test_case.input_size}, &result,
325 <<
"for case " << test_case.input;
326 ASSERT_EQ(test_case.expected_size, result_size);
327 const uint8_t* result_ptr = result.get();
328 for (size_t j = 0; j < result_size; ++j) {
329 EXPECT_EQ(test_case.expected[j], result_ptr[j])
330 <<
"for case " << test_case.input <<
" char " << j;
337 EXPECT_EQ(L"", PDF_DecodeText(ToSpan(
"")));
340 EXPECT_EQ(L"the quick\tfox", PDF_DecodeText(ToSpan(
"the quick\tfox")));
343 EXPECT_EQ(L"\x0330\x0331",
344 PDF_DecodeText(ToSpan(
"\xEF\xBB\xBF\xCC\xB0\xCC\xB1")));
347 EXPECT_EQ(L"\x0330\x0331",
348 PDF_DecodeText(ToSpan(
"\xFE\xFF\x03\x30\x03\x31")));
352 L"\x7F51\x9875\x0020\x56FE\x7247\x0020"
353 L"\x8D44\x8BAF\x66F4\x591A\x0020\x00BB",
355 ToSpan(
"\xFE\xFF\x7F\x51\x98\x75\x00\x20\x56\xFE\x72\x47\x00"
356 "\x20\x8D\x44\x8B\xAF\x66\xF4\x59\x1A\x00\x20\x00\xBB")));
359 EXPECT_EQ(L"🎨", PDF_DecodeText(ToSpan(
"\xEF\xBB\xBF\xF0\x9F\x8E\xA8")));
362 EXPECT_EQ(L"🎨", PDF_DecodeText(ToSpan(
"\xFE\xFF\xD8\x3C\xDF\xA8")));