summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cfdf_document.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp17
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp10
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp29
4 files changed, 33 insertions, 27 deletions
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp
index 03cc655a0a..85e2f6ef04 100644
--- a/core/fpdfapi/parser/cfdf_document.cpp
+++ b/core/fpdfapi/parser/cfdf_document.cpp
@@ -13,6 +13,7 @@
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
+#include "core/fxcrt/cfx_memorystream.h"
#include "third_party/base/ptr_util.h"
CFDF_Document::CFDF_Document()
@@ -39,7 +40,8 @@ std::unique_ptr<CFDF_Document> CFDF_Document::ParseFile(
std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(uint8_t* pData,
uint32_t size) {
- return CFDF_Document::ParseFile(IFX_MemoryStream::Create(pData, size));
+ return CFDF_Document::ParseFile(
+ pdfium::MakeRetain<CFX_MemoryStream>(pData, size, false));
}
void CFDF_Document::ParseStream(
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index f99cb467e5..41a3f0dae2 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -21,6 +21,7 @@
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
+#include "core/fxcrt/cfx_memorystream.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/numerics/safe_conversions.h"
@@ -716,8 +717,8 @@ bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) {
if (m_pLinearized)
return true;
- CFX_RetainPtr<IFX_MemoryStream> file =
- IFX_MemoryStream::Create(pData, (size_t)dwLen, false);
+ auto file = pdfium::MakeRetain<CFX_MemoryStream>(
+ pData, static_cast<size_t>(dwLen), false);
int32_t offset = GetHeaderOffset(file);
if (offset == -1) {
m_docStatus = PDF_DATAAVAIL_ERROR;
@@ -756,8 +757,8 @@ bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) {
uint8_t buffer[1024];
m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
- CFX_RetainPtr<IFX_MemoryStream> file =
- IFX_MemoryStream::Create(buffer, (size_t)dwSize, false);
+ auto file = pdfium::MakeRetain<CFX_MemoryStream>(
+ buffer, static_cast<size_t>(dwSize), false);
m_syntaxParser.InitParser(file, 0);
m_syntaxParser.RestorePos(dwSize - 1);
@@ -804,8 +805,8 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(DownloadHints* pHints,
m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize);
- CFX_RetainPtr<IFX_MemoryStream> file =
- IFX_MemoryStream::Create(pBuf, (size_t)iSize, false);
+ auto file = pdfium::MakeRetain<CFX_MemoryStream>(
+ pBuf, static_cast<size_t>(iSize), false);
m_parser.m_pSyntax->InitParser(file, 0);
bool bNumber;
@@ -1049,8 +1050,8 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) {
if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize))
return false;
- CFX_RetainPtr<IFX_MemoryStream> file =
- IFX_MemoryStream::Create(pBuf, (size_t)iSize, false);
+ auto file = pdfium::MakeRetain<CFX_MemoryStream>(
+ pBuf, static_cast<size_t>(iSize), false);
m_syntaxParser.InitParser(file, 0);
std::unique_ptr<CPDF_Object> pTrailer(
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index c18a183a33..86428ab9d7 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -22,6 +22,7 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
+#include "core/fxcrt/cfx_memorystream.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/ptr_util.h"
@@ -1114,8 +1115,9 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject(
if (!pObjStream)
return nullptr;
- CFX_RetainPtr<IFX_MemoryStream> file = IFX_MemoryStream::Create(
- (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), false);
+ auto file = pdfium::MakeRetain<CFX_MemoryStream>(
+ const_cast<uint8_t*>(pObjStream->GetData()),
+ static_cast<size_t>(pObjStream->GetSize()), false);
CPDF_SyntaxParser syntax;
syntax.InitParser(file, 0);
const int32_t offset = GetStreamFirst(pObjStream);
@@ -1194,8 +1196,8 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum,
int32_t offset = GetStreamFirst(pObjStream);
const uint8_t* pData = pObjStream->GetData();
uint32_t totalsize = pObjStream->GetSize();
- CFX_RetainPtr<IFX_MemoryStream> file =
- IFX_MemoryStream::Create((uint8_t*)pData, (size_t)totalsize, false);
+ auto file = pdfium::MakeRetain<CFX_MemoryStream>(
+ const_cast<uint8_t*>(pData), static_cast<size_t>(totalsize), false);
CPDF_SyntaxParser syntax;
syntax.InitParser(file, 0);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
index 5c7aa6054b..249276f29a 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
@@ -8,6 +8,7 @@
#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_memorystream.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_stream.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -18,7 +19,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Empty string.
uint8_t data[] = "";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 0, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 0, false), 0);
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(0, parser.SavePos());
}
@@ -27,7 +28,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Blank string.
uint8_t data[] = " ";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 2, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 2, false), 0);
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(2, parser.SavePos());
}
@@ -36,7 +37,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Skips unknown characters.
uint8_t data[] = "z12b";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false), 0);
EXPECT_EQ("\x12\xb0", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -45,7 +46,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Skips unknown characters.
uint8_t data[] = "*<&*#$^&@1";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 10, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 10, false), 0);
EXPECT_EQ("\x10", parser.ReadHexString());
EXPECT_EQ(10, parser.SavePos());
}
@@ -54,7 +55,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Skips unknown characters.
uint8_t data[] = "\x80zab";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false), 0);
EXPECT_EQ("\xab", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -63,7 +64,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Skips unknown characters.
uint8_t data[] = "\xffzab";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false), 0);
EXPECT_EQ("\xab", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -72,7 +73,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Regular conversion.
uint8_t data[] = "1A2b>abcd";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 9, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 9, false), 0);
EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
EXPECT_EQ(5, parser.SavePos());
}
@@ -81,7 +82,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Position out of bounds.
uint8_t data[] = "12ab>";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 5, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 5, false), 0);
parser.RestorePos(5);
EXPECT_EQ("", parser.ReadHexString());
@@ -103,7 +104,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Missing ending >.
uint8_t data[] = "1A2b";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 4, false), 0);
EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -112,7 +113,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Missing ending >.
uint8_t data[] = "12abz";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 5, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 5, false), 0);
EXPECT_EQ("\x12\xab", parser.ReadHexString());
EXPECT_EQ(5, parser.SavePos());
}
@@ -121,7 +122,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Uneven number of bytes.
uint8_t data[] = "1A2>asdf";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 8, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 8, false), 0);
EXPECT_EQ("\x1a\x20", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -130,7 +131,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Uneven number of bytes.
uint8_t data[] = "1A2zasdf";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 8, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 8, false), 0);
EXPECT_EQ("\x1a\x2a\xdf", parser.ReadHexString());
EXPECT_EQ(8, parser.SavePos());
}
@@ -139,7 +140,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
// Just ending character.
uint8_t data[] = ">";
CPDF_SyntaxParser parser;
- parser.InitParser(IFX_MemoryStream::Create(data, 1, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 1, false), 0);
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(1, parser.SavePos());
}
@@ -149,7 +150,7 @@ TEST(cpdf_syntax_parser, GetInvalidReference) {
CPDF_SyntaxParser parser;
// Data with a reference with number CPDF_Object::kInvalidObjNum
uint8_t data[] = "4294967295 0 R";
- parser.InitParser(IFX_MemoryStream::Create(data, 14, false), 0);
+ parser.InitParser(pdfium::MakeRetain<CFX_MemoryStream>(data, 14, false), 0);
std::unique_ptr<CPDF_Object> ref =
parser.GetObject(nullptr, CPDF_Object::kInvalidObjNum, 0, false);
EXPECT_FALSE(ref);