144 CPDF_TestParser parser;
145 std::string test_file =
147 ASSERT_FALSE(test_file.empty());
151 const FX_FILESIZE offsets[] = {0, 15, 61, 154, 296, 374, 450};
152 const uint16_t versions[] = {0, 0, 2, 4, 6, 8, 0};
153 for (size_t i = 0; i <
std::size(offsets); ++i)
154 EXPECT_EQ(offsets[i], GetObjInfo(parser, i).pos);
155 for (size_t i = 0; i <
std::size(versions); ++i)
156 EXPECT_EQ(versions[i], GetObjInfo(parser, i).gennum);
159 ASSERT_TRUE(cross_ref_table);
175 static const unsigned char kXrefTable[] =
178 "0000000003 65535 f \n"
179 "0000000017 00000 n \n"
180 "0000000081 00000 n \n"
181 "0000000000 00007 f \n"
182 "0000000331 00000 n \n"
183 "0000000409 00000 n \n"
185 CPDF_TestParser parser;
189 static const FX_FILESIZE kOffsets[] = {0, 17, 81, 0, 331, 409};
197 static_assert(
std::size(kOffsets) ==
std::size(kTypes),
198 "kOffsets / kTypes size mismatch");
199 for (size_t i = 0; i <
std::size(kOffsets); ++i) {
200 EXPECT_EQ(kOffsets[i], GetObjInfo(parser, i).pos);
201 EXPECT_EQ(kTypes[i], GetObjInfo(parser, i).type);
205 static const unsigned char kXrefTable[] =
208 "0000000000 65535 f \n"
210 "0000025325 00000 n \n"
212 "0000025518 00002 n \n"
213 "0000025635 00000 n \n"
215 "0000025777 00000 n \n"
217 CPDF_TestParser parser;
221 static const FX_FILESIZE kOffsets[] = {0, 0, 0, 25325, 0, 0, 0,
222 0, 25518, 25635, 0, 0, 25777};
237 static_assert(
std::size(kOffsets) ==
std::size(kTypes),
238 "kOffsets / kTypes size mismatch");
239 for (size_t i = 0; i <
std::size(kOffsets); ++i) {
240 EXPECT_EQ(kOffsets[i], GetObjInfo(parser, i).pos);
241 EXPECT_EQ(kTypes[i], GetObjInfo(parser, i).type);
245 static const unsigned char kXrefTable[] =
248 "0000000000 65535 f \n"
250 "0000025325 00000 n \n"
252 "0000000000 65535 f \n"
253 "0000025635 00000 n \n"
255 "0000025777 00000 n \n"
257 CPDF_TestParser parser;
261 static const FX_FILESIZE kOffsets[] = {0, 0, 0, 25325, 0, 0, 0,
262 0, 0, 25635, 0, 0, 25777};
277 static_assert(
std::size(kOffsets) ==
std::size(kTypes),
278 "kOffsets / kTypes size mismatch");
279 for (size_t i = 0; i <
std::size(kOffsets); ++i) {
280 EXPECT_EQ(kOffsets[i], GetObjInfo(parser, i).pos);
281 EXPECT_EQ(kTypes[i], GetObjInfo(parser, i).type);
285 static const unsigned char kXrefTable[] =
288 "0000000002 65535 f \n"
289 "0000000023 00000 n \n"
290 "0000000003 65535 f \n"
291 "0000000004 65535 f \n"
292 "0000000000 65535 f \n"
293 "0000000045 00000 n \n"
294 "0000000179 00000 n \n"
296 CPDF_TestParser parser;
300 static const FX_FILESIZE kOffsets[] = {0, 23, 0, 0, 0, 45, 179};
309 static_assert(
std::size(kOffsets) ==
std::size(kTypes),
310 "kOffsets / kTypes size mismatch");
311 for (size_t i = 0; i <
std::size(kOffsets); ++i) {
312 EXPECT_EQ(kOffsets[i], GetObjInfo(parser, i).pos);
313 EXPECT_EQ(kTypes[i], GetObjInfo(parser, i).type);
320 std::string xref_table =
"xref \n 0 2048 \n";
321 xref_table.reserve(41000);
322 for (
int i = 0; i < 2048; ++i) {
324 snprintf(buffer,
sizeof(buffer),
"%010d 00000 n \n", i + 1);
325 xref_table += buffer;
327 xref_table +=
"trail";
328 CPDF_TestParser parser;
330 pdfium::make_span(
reinterpret_cast<
const uint8_t*>(xref_table.c_str()),
331 xref_table.size())
));
334 for (size_t i = 0; i < 2048; ++i) {
335 EXPECT_EQ(
static_cast<
int>(i) + 1, GetObjInfo(parser, i).pos);
337 GetObjInfo(parser, i).type);
357 static constexpr FX_FILESIZE kTestHeaderOffset = 765;
358 std::string test_file =
360 ASSERT_FALSE(test_file.empty());
362 IFX_SeekableReadStream::CreateFromFilename(test_file.c_str());
363 ASSERT_TRUE(pFileAccess);
365 std::vector<
unsigned char> data(pFileAccess->GetSize() + kTestHeaderOffset);
366 ASSERT_TRUE(pFileAccess->ReadBlockAtOffset(
367 pdfium::make_span(data).subspan(kTestHeaderOffset), 0));
368 CPDF_TestParser parser;
373 parser.ParseIndirectObjectAt(100940, 0);
374 ASSERT_TRUE(cross_ref_v5_obj);
375 EXPECT_EQ(75u, cross_ref_v5_obj->GetObjNum());
379 static constexpr FX_FILESIZE kTestHeaderOffset = 765;
381 ASSERT_FALSE(test_file.empty());
383 IFX_SeekableReadStream::CreateFromFilename(test_file.c_str());
384 ASSERT_TRUE(pFileAccess);
386 std::vector<
unsigned char> data(pFileAccess->GetSize() + kTestHeaderOffset);
387 ASSERT_TRUE(pFileAccess->ReadBlockAtOffset(
388 pdfium::make_span(data).subspan(kTestHeaderOffset), 0));
390 CPDF_TestParser parser;
392 EXPECT_TRUE(parser.ParseLinearizedHeader());
395 ASSERT_TRUE(cross_ref_table);
441 "Unexpected kMaxObjectNumber");
442 const unsigned char kData[] =
443 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
445 " /Filter /ASCIIHexDecode\n"
446 " /Index [4194303 3]\n"
460 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
462 EXPECT_FALSE(parser().xref_table_rebuilt());
463 ASSERT_TRUE(parser().GetCrossRefTable());
464 const auto& objects_info = parser().GetCrossRefTable()->objects_info();
477 EXPECT_THAT(objects_info, ElementsAre(Pair(4194303, only_valid_object),
478 Pair(4194305, placeholder_object)));
483 const unsigned char kData[] =
484 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
486 " /Filter /ASCIIHexDecode\n"
500 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
502 EXPECT_FALSE(parser().xref_table_rebuilt());
505 ASSERT_TRUE(cross_ref_table);
507 const auto& objects_info = cross_ref_table->objects_info();
516 EXPECT_THAT(objects_info, ElementsAre(Pair(1, expected_objects[0]),
517 Pair(2, expected_objects[1])));
621 const unsigned char kData[] =
622 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
624 " /Filter /ASCIIHexDecode\n"
638 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
640 EXPECT_FALSE(parser().xref_table_rebuilt());
641 ASSERT_TRUE(parser().GetCrossRefTable());
642 const auto& objects_info = parser().GetCrossRefTable()->objects_info();
648 EXPECT_THAT(objects_info, ElementsAre(Pair(0, expected_result[0]),
649 Pair(1, expected_result[1])));
654 const unsigned char kData[] =
655 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
657 " /Filter /ASCIIHexDecode\n"
660 " /Index [2 1 4 2 80 3]\n"
676 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
678 EXPECT_FALSE(parser().xref_table_rebuilt());
679 ASSERT_TRUE(parser().GetCrossRefTable());
680 const auto& objects_info = parser().GetCrossRefTable()->objects_info();
692 ElementsAre(Pair(2, expected_result[0]), Pair(4, expected_result[1]),
693 Pair(5, expected_result[2]), Pair(80, expected_result[3]),
694 Pair(81, expected_result[4]), Pair(82, expected_result[5])));
699 const unsigned char kData[] =
700 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
702 " /Filter /ASCIIHexDecode\n"
705 " /Index [2 2 3 1]\n"
718 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
720 EXPECT_FALSE(parser().xref_table_rebuilt());
721 ASSERT_TRUE(parser().GetCrossRefTable());
722 const auto& objects_info = parser().GetCrossRefTable()->objects_info();
730 EXPECT_THAT(objects_info, ElementsAre(Pair(2, expected_result[0]),
731 Pair(3, expected_result[1])));
736 const unsigned char kData[] =
737 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
739 " /Filter /ASCIIHexDecode\n"
742 " /Index [3 2 2 1]\n"
755 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
757 EXPECT_FALSE(parser().xref_table_rebuilt());
758 ASSERT_TRUE(parser().GetCrossRefTable());
759 const auto& objects_info = parser().GetCrossRefTable()->objects_info();
767 EXPECT_THAT(objects_info, ElementsAre(Pair(2, expected_result[0]),
768 Pair(3, expected_result[1]),
769 Pair(4, expected_result[2])));
775 const unsigned char kData[] =
776 "%PDF1-7\n%\xa0\xf2\xa4\xf4\n"
778 " /Filter /ASCIIHexDecode\n"
781 " /Index [2 1 80 2]\n"
794 ASSERT_TRUE(parser().InitTestFromBuffer(kData));
796 EXPECT_FALSE(parser().xref_table_rebuilt());
797 ASSERT_TRUE(parser().GetCrossRefTable());
798 const auto& objects_info = parser().GetCrossRefTable()->objects_info();
805 EXPECT_THAT(objects_info, ElementsAre(Pair(2, expected_result[0]),
806 Pair(80, expected_result[1]),
807 Pair(81, expected_result[2])));