summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-14 18:26:36 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-14 18:26:36 +0000
commit88798cff29934b58e0a8d81e94005472d612b964 (patch)
tree3b5a25faa2a627ac30de219b89c8152a9fff2f27 /core
parentb9c3e2712f75363372622282023143b86b72f2df (diff)
downloadpdfium-88798cff29934b58e0a8d81e94005472d612b964.tar.xz
Remove CFX_BufferSeekableReadStream.
Replace it with CFX_ReadOnlyMemoryStream, which does the same thing. Take some checks from CFX_BufferSeekableReadStream and add them CFX_ReadOnlyMemoryStream. Change-Id: I25554c3aec3ec96967f8df16ca68a64dba121b6f Reviewed-on: https://pdfium-review.googlesource.com/40070 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_parser_unittest.cpp5
-rw-r--r--core/fpdfapi/parser/cpdf_read_validator_unittest.cpp9
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp33
-rw-r--r--core/fxcrt/cfx_readonlymemorystream.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp6
-rw-r--r--core/fxcrt/xml/cfx_xmlparser_unittest.cpp6
8 files changed, 34 insertions, 35 deletions
diff --git a/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp b/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp
index eab7330cf6..6cdc3f1817 100644
--- a/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_cross_ref_avail_unittest.cpp
@@ -8,7 +8,7 @@
#include <string>
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
-#include "testing/fx_string_testhelpers.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/base/ptr_util.h"
@@ -17,7 +17,7 @@ namespace {
std::unique_ptr<CPDF_SyntaxParser> MakeParserForBuffer(
pdfium::span<const uint8_t> buffer) {
return pdfium::MakeUnique<CPDF_SyntaxParser>(
- pdfium::MakeRetain<CFX_BufferSeekableReadStream>(buffer));
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(buffer));
}
} // namespace
diff --git a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
index 97ba434768..c372d74a00 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_hint_tables_unittest.cpp
@@ -16,8 +16,8 @@
#include "core/fpdfapi/parser/cpdf_read_validator.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_stream.h"
-#include "testing/fx_string_testhelpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/utils/path_service.h"
@@ -48,7 +48,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>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::as_bytes(pdfium::make_span(inline_data))));
std::unique_ptr<CPDF_Dictionary> dict =
ToDictionary(parser.GetObjectBody(nullptr));
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index d5166fbdf0..00f3770e87 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -11,10 +11,10 @@
#include "core/fpdfapi/parser/cpdf_object.h"
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/retain_ptr.h"
-#include "testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/utils/path_service.h"
@@ -50,8 +50,7 @@ class CPDF_TestParser : public CPDF_Parser {
bool InitTestFromBufferWithOffset(pdfium::span<const uint8_t> buffer,
FX_FILESIZE header_offset) {
m_pSyntax = CPDF_SyntaxParser::CreateForTesting(
- pdfium::MakeRetain<CFX_BufferSeekableReadStream>(buffer),
- header_offset);
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(buffer), header_offset);
return true;
}
diff --git a/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp b/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp
index ccfb451dd8..640269884d 100644
--- a/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp
@@ -8,6 +8,7 @@
#include <utility>
#include <vector>
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -65,7 +66,7 @@ class MockDownloadHints : public CPDF_DataAvail::DownloadHints {
TEST(CPDF_ReadValidatorTest, UnavailableData) {
std::vector<uint8_t> test_data(kTestDataSize);
- auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data);
+ auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
MockFileAvail file_avail;
auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
@@ -88,7 +89,7 @@ TEST(CPDF_ReadValidatorTest, UnavailableData) {
TEST(CPDF_ReadValidatorTest, UnavailableDataWithHints) {
std::vector<uint8_t> test_data(kTestDataSize);
- auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data);
+ auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
MockFileAvail file_avail;
auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
@@ -143,7 +144,7 @@ TEST(CPDF_ReadValidatorTest, ReadError) {
TEST(CPDF_ReadValidatorTest, IntOverflow) {
std::vector<uint8_t> test_data(kTestDataSize);
- auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data);
+ auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
MockFileAvail file_avail;
auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
@@ -241,7 +242,7 @@ TEST(CPDF_ReadValidatorTest, SessionReset) {
TEST(CPDF_ReadValidatorTest, CheckDataRangeAndRequestIfUnavailable) {
std::vector<uint8_t> test_data(kTestDataSize);
- auto file = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(test_data);
+ auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
MockFileAvail file_avail;
auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
index 498eddf12b..5b06d33d4b 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
@@ -8,8 +8,8 @@
#include "core/fpdfapi/parser/cpdf_object.h"
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_extension.h"
-#include "testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/utils/path_service.h"
@@ -17,7 +17,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Empty string.
static const uint8_t data[] = "";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 0)));
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(0, parser.GetPos());
@@ -26,7 +26,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Blank string.
static const uint8_t data[] = " ";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 2)));
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(2, parser.GetPos());
@@ -35,7 +35,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
static const uint8_t data[] = "z12b";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 4)));
EXPECT_EQ("\x12\xb0", parser.ReadHexString());
EXPECT_EQ(4, parser.GetPos());
@@ -44,7 +44,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
static const uint8_t data[] = "*<&*#$^&@1";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 10)));
EXPECT_EQ("\x10", parser.ReadHexString());
EXPECT_EQ(10, parser.GetPos());
@@ -53,7 +53,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
static const uint8_t data[] = "\x80zab";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 4)));
EXPECT_EQ("\xab", parser.ReadHexString());
EXPECT_EQ(4, parser.GetPos());
@@ -62,7 +62,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
static const uint8_t data[] = "\xffzab";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 4)));
EXPECT_EQ("\xab", parser.ReadHexString());
EXPECT_EQ(4, parser.GetPos());
@@ -71,7 +71,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Regular conversion.
static const uint8_t data[] = "1A2b>abcd";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 9)));
EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
EXPECT_EQ(5, parser.GetPos());
@@ -80,7 +80,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Position out of bounds.
static const uint8_t data[] = "12ab>";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 5)));
parser.SetPos(5);
EXPECT_EQ("", parser.ReadHexString());
@@ -102,7 +102,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Missing ending >.
static const uint8_t data[] = "1A2b";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 4)));
EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
EXPECT_EQ(4, parser.GetPos());
@@ -111,7 +111,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Missing ending >.
static const uint8_t data[] = "12abz";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 5)));
EXPECT_EQ("\x12\xab", parser.ReadHexString());
EXPECT_EQ(5, parser.GetPos());
@@ -120,7 +120,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Uneven number of bytes.
static const uint8_t data[] = "1A2>asdf";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 8)));
EXPECT_EQ("\x1a\x20", parser.ReadHexString());
EXPECT_EQ(4, parser.GetPos());
@@ -129,7 +129,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Uneven number of bytes.
static const uint8_t data[] = "1A2zasdf";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 8)));
EXPECT_EQ("\x1a\x2a\xdf", parser.ReadHexString());
EXPECT_EQ(8, parser.GetPos());
@@ -138,7 +138,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Just ending character.
static const uint8_t data[] = ">";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 1)));
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(1, parser.GetPos());
@@ -148,7 +148,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
TEST(cpdf_syntax_parser, GetInvalidReference) {
// Data with a reference with number CPDF_Object::kInvalidObjNum
static const uint8_t data[] = "4294967295 0 R";
- CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::make_span(data, 14)));
std::unique_ptr<CPDF_Object> ref = parser.GetObjectBody(nullptr);
EXPECT_FALSE(ref);
@@ -156,8 +156,7 @@ TEST(cpdf_syntax_parser, GetInvalidReference) {
TEST(cpdf_syntax_parser, PeekNextWord) {
static const uint8_t data[] = " WORD ";
- CPDF_SyntaxParser parser(
- pdfium::MakeRetain<CFX_BufferSeekableReadStream>(data));
+ CPDF_SyntaxParser parser(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(data));
EXPECT_EQ("WORD", parser.PeekNextWord(nullptr));
EXPECT_EQ("WORD", parser.GetNextWord(nullptr));
}
diff --git a/core/fxcrt/cfx_readonlymemorystream.cpp b/core/fxcrt/cfx_readonlymemorystream.cpp
index a01ed2e474..0a1a53a456 100644
--- a/core/fxcrt/cfx_readonlymemorystream.cpp
+++ b/core/fxcrt/cfx_readonlymemorystream.cpp
@@ -21,7 +21,7 @@ FX_FILESIZE CFX_ReadOnlyMemoryStream::GetSize() {
bool CFX_ReadOnlyMemoryStream::ReadBlock(void* buffer,
FX_FILESIZE offset,
size_t size) {
- if (offset < 0)
+ if (!buffer || offset < 0 || size == 0)
return false;
FX_SAFE_SIZE_T pos = size;
diff --git a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
index 0109ab2985..c1fbad5f0f 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlinstruction_unittest.cpp
@@ -4,10 +4,10 @@
#include "core/fxcrt/xml/cfx_xmlinstruction.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlparser.h"
-#include "testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/string_write_stream.h"
#include "testing/test_support.h"
@@ -86,7 +86,7 @@ TEST(CFX_XMLInstructionTest, ParseAndReSave) {
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
"<node></node>";
- auto in_stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ auto in_stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::as_bytes(pdfium::make_span(input)));
CFX_XMLParser parser(in_stream);
@@ -119,7 +119,7 @@ TEST(CFX_XMLInstructionTest, ParseAndReSaveInnerInstruction) {
"<?acrobat http://www.xfa.org/schema/xfa-template/3.3/ Display:1 ?>\n"
"</node>";
- auto in_stream = pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
+ auto in_stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
pdfium::as_bytes(pdfium::make_span(input)));
CFX_XMLParser parser(in_stream);
diff --git a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
index c1236ce182..86d340ea83 100644
--- a/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser_unittest.cpp
@@ -6,11 +6,11 @@
#include <memory>
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlinstruction.h"
-#include "testing/fx_string_testhelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
#include "third_party/base/ptr_util.h"
@@ -18,8 +18,8 @@
class CFX_XMLParserTest : public testing::Test {
public:
std::unique_ptr<CFX_XMLDocument> Parse(pdfium::span<const char> input) {
- CFX_XMLParser parser(pdfium::MakeRetain<CFX_BufferSeekableReadStream>(
- pdfium::as_bytes(input)));
+ CFX_XMLParser parser(
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pdfium::as_bytes(input)));
return parser.Parse();
}
};