diff options
author | Lei Zhang <thestig@chromium.org> | 2018-07-25 20:09:58 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-25 20:09:58 +0000 |
commit | 9160cec4c8a0559586d90a6dcf9b2a2551a5fbd8 (patch) | |
tree | 8d219e56835d1e589328276d03c7d495cb2298f7 /core/fpdfapi | |
parent | 8481c71db0e3abed7bd12669116b223a65bebbb4 (diff) | |
download | pdfium-9160cec4c8a0559586d90a6dcf9b2a2551a5fbd8.tar.xz |
Change CFX_BufferSeekableReadStream to take a span.
Change-Id: Ib9e20fdfc637b2ba0358586e23ad72454b0b8ad1
Reviewed-on: https://pdfium-review.googlesource.com/38851
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp | 34 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser_unittest.cpp | 27 |
3 files changed, 25 insertions, 39 deletions
diff --git a/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp b/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp index 4ee6b59ad5..eab7330cf6 100644 --- a/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp @@ -15,10 +15,9 @@ namespace { std::unique_ptr<CPDF_SyntaxParser> MakeParserForBuffer( - const unsigned char* buffer, - size_t buffer_size) { + pdfium::span<const uint8_t> buffer) { return pdfium::MakeUnique<CPDF_SyntaxParser>( - pdfium::MakeRetain<CFX_BufferSeekableReadStream>(buffer, buffer_size)); + pdfium::MakeRetain<CFX_BufferSeekableReadStream>(buffer)); } } // namespace @@ -39,7 +38,7 @@ TEST(CPDF_CrossRefAvailTest, CheckCrossRefV4) { "/Info 15 0 R/Size 16>>"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(xref_table, FX_ArraySize(xref_table)); + auto parser = MakeParserForBuffer(xref_table); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); @@ -56,7 +55,7 @@ TEST(CPDF_CrossRefAvailTest, CheckCrossRefStream) { "endobj\n"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(xref_stream, FX_ArraySize(xref_stream)); + auto parser = MakeParserForBuffer(xref_stream); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); @@ -74,7 +73,7 @@ TEST(CPDF_CrossRefAvailTest, IncorrectStartOffset) { const FX_FILESIZE last_crossref_offset = 70000; - auto parser = MakeParserForBuffer(xref_stream, FX_ArraySize(xref_stream)); + auto parser = MakeParserForBuffer(xref_stream); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); @@ -91,7 +90,7 @@ TEST(CPDF_CrossRefAvailTest, IncorrectPrevOffset) { "endobj\n"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(xref_stream, FX_ArraySize(xref_stream)); + auto parser = MakeParserForBuffer(xref_stream); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataError, cross_ref_avail->CheckAvail()); @@ -113,7 +112,7 @@ TEST(CPDF_CrossRefAvailTest, IncorrectPrevStreamOffset) { "/Info 15 0 R/Size 16 /XRefStm 70000>>"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(xref_table, FX_ArraySize(xref_table)); + auto parser = MakeParserForBuffer(xref_table); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataError, cross_ref_avail->CheckAvail()); @@ -125,8 +124,7 @@ TEST(CPDF_CrossRefAvailTest, IncorrectData) { "wfoihoiwfghouiafghwoigahfi"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = - MakeParserForBuffer(incorrect_data, FX_ArraySize(incorrect_data)); + auto parser = MakeParserForBuffer(incorrect_data); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataError, cross_ref_avail->CheckAvail()); @@ -174,8 +172,7 @@ TEST(CPDF_CrossRefAvailTest, ThreeCrossRefV4) { FXSYS_itoa(static_cast<int>(prev_offset), int_buffer, 10) + ">>\n"; const FX_FILESIZE last_crossref_offset = static_cast<FX_FILESIZE>(cur_offset); - auto parser = MakeParserForBuffer( - reinterpret_cast<const unsigned char*>(table.data()), table.size()); + auto parser = MakeParserForBuffer(pdfium::as_bytes(pdfium::make_span(table))); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataAvailable, cross_ref_avail->CheckAvail()); @@ -219,8 +216,7 @@ TEST(CPDF_CrossRefAvailTest, ThreeCrossRefV5) { "endobj\n"; const FX_FILESIZE last_crossref_offset = static_cast<FX_FILESIZE>(cur_offset); - auto parser = MakeParserForBuffer( - reinterpret_cast<const unsigned char*>(table.data()), table.size()); + auto parser = MakeParserForBuffer(pdfium::as_bytes(pdfium::make_span(table))); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataAvailable, cross_ref_avail->CheckAvail()); @@ -269,8 +265,7 @@ TEST(CPDF_CrossRefAvailTest, Mixed) { FXSYS_itoa(first_v5_table_offset, int_buffer, 10) + ">>\n"; const FX_FILESIZE last_crossref_offset = last_v4_table_offset; - auto parser = MakeParserForBuffer( - reinterpret_cast<const unsigned char*>(table.data()), table.size()); + auto parser = MakeParserForBuffer(pdfium::as_bytes(pdfium::make_span(table))); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataAvailable, cross_ref_avail->CheckAvail()); @@ -284,8 +279,7 @@ TEST(CPDF_CrossRefAvailTest, CrossRefV5IsNotStream) { "endobj\n"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(invalid_xref_stream, - FX_ArraySize(invalid_xref_stream)); + auto parser = MakeParserForBuffer(invalid_xref_stream); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataError, cross_ref_avail->CheckAvail()); @@ -308,7 +302,7 @@ TEST(CPDF_CrossRefAvailTest, CrossRefV4WithEncryptRef) { "/Info 15 0 R/Size 16>>"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(xref_table, FX_ArraySize(xref_table)); + auto parser = MakeParserForBuffer(xref_table); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataError, cross_ref_avail->CheckAvail()); @@ -324,7 +318,7 @@ TEST(CPDF_CrossRefAvailTest, CrossRefStreamWithEncryptRef) { "endobj\n"; const FX_FILESIZE last_crossref_offset = 0; - auto parser = MakeParserForBuffer(xref_stream, FX_ArraySize(xref_stream)); + auto parser = MakeParserForBuffer(xref_stream); auto cross_ref_avail = pdfium::MakeUnique<CPDF_CrossRefAvail>( parser.get(), last_crossref_offset); EXPECT_EQ(CPDF_DataAvail::DataError, cross_ref_avail->CheckAvail()); diff --git a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp index 34c1694c59..dba39f5594 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp @@ -49,8 +49,7 @@ class TestLinearizedHeader : public CPDF_LinearizedHeader { static std::unique_ptr<CPDF_LinearizedHeader> MakeHeader( const std::string& inline_data) { CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>( - reinterpret_cast<const unsigned char*>(inline_data.data()), - inline_data.size())); + pdfium::as_bytes(pdfium::make_span(inline_data)))); std::unique_ptr<CPDF_Dictionary> dict = ToDictionary(parser.GetObjectBody(nullptr)); ASSERT(dict); diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp index 2e7e06066b..d5166fbdf0 100644 --- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp @@ -47,17 +47,16 @@ class CPDF_TestParser : public CPDF_Parser { } // Setup reading from a buffer and initial states. - bool InitTestFromBufferWithOffset(const unsigned char* buffer, - size_t len, + bool InitTestFromBufferWithOffset(pdfium::span<const uint8_t> buffer, FX_FILESIZE header_offset) { m_pSyntax = CPDF_SyntaxParser::CreateForTesting( - pdfium::MakeRetain<CFX_BufferSeekableReadStream>(buffer, len), + pdfium::MakeRetain<CFX_BufferSeekableReadStream>(buffer), header_offset); return true; } - bool InitTestFromBuffer(const unsigned char* buffer, size_t len) { - return InitTestFromBufferWithOffset(buffer, len, 0 /*header_offset*/); + bool InitTestFromBuffer(pdfium::span<const uint8_t> buffer) { + return InitTestFromBufferWithOffset(buffer, 0 /*header_offset*/); } private: @@ -109,8 +108,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { "0000000409 00000 n \n" "trail"; // Needed to end cross ref table reading. CPDF_TestParser parser; - ASSERT_TRUE( - parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); + ASSERT_TRUE(parser.InitTestFromBuffer(xref_table)); ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 17, 81, 0, 331, 409}; @@ -140,8 +138,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { "0000025777 00000 n \n" "trail"; // Needed to end cross ref table reading. CPDF_TestParser parser; - ASSERT_TRUE( - parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); + ASSERT_TRUE(parser.InitTestFromBuffer(xref_table)); ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0, @@ -179,8 +176,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { "0000025777 00000 n \n" "trail"; // Needed to end cross ref table reading. CPDF_TestParser parser; - ASSERT_TRUE( - parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); + ASSERT_TRUE(parser.InitTestFromBuffer(xref_table)); ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0, @@ -217,8 +213,7 @@ TEST(cpdf_parser, LoadCrossRefV4) { "0000000179 00000 n \n" "trail"; // Needed to end cross ref table reading. CPDF_TestParser parser; - ASSERT_TRUE( - parser.InitTestFromBuffer(xref_table, FX_ArraySize(xref_table))); + ASSERT_TRUE(parser.InitTestFromBuffer(xref_table)); ASSERT_TRUE(parser.LoadCrossRefV4(0, false)); const FX_FILESIZE offsets[] = {0, 23, 0, 0, 0, 45, 179}; @@ -264,8 +259,7 @@ TEST(cpdf_parser, ParseStartXRefWithHeaderOffset) { ASSERT_TRUE(pFileAccess->ReadBlock(&data.front() + kTestHeaderOffset, 0, pFileAccess->GetSize())); CPDF_TestParser parser; - parser.InitTestFromBufferWithOffset(&data.front(), data.size(), - kTestHeaderOffset); + parser.InitTestFromBufferWithOffset(data, kTestHeaderOffset); EXPECT_EQ(100940, parser.ParseStartXRef()); std::unique_ptr<CPDF_Object> cross_ref_v5_obj = @@ -286,8 +280,7 @@ TEST(cpdf_parser, ParseLinearizedWithHeaderOffset) { ASSERT_TRUE(pFileAccess->ReadBlock(&data.front() + kTestHeaderOffset, 0, pFileAccess->GetSize())); CPDF_TestParser parser; - parser.InitTestFromBufferWithOffset(&data.front(), data.size(), - kTestHeaderOffset); + parser.InitTestFromBufferWithOffset(data, kTestHeaderOffset); EXPECT_TRUE(parser.ParseLinearizedHeader()); } |