summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp2
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentmanager.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_crypto_handler.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp10
-rw-r--r--core/fpdfapi/parser/cpdf_stream.cpp36
-rw-r--r--core/fpdfapi/parser/cpdf_stream.h14
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp3
-rw-r--r--core/fpdfdoc/cpdf_metadata_unittest.cpp16
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp4
-rw-r--r--core/fxcrt/cfx_seekablemultistream_unittest.cpp6
-rw-r--r--fpdfsdk/formfiller/cba_fontmap.cpp2
-rw-r--r--fpdfsdk/fpdf_annot.cpp4
-rw-r--r--fpdfsdk/fpdf_edittext.cpp4
-rw-r--r--fpdfsdk/fpdf_flatten.cpp7
-rw-r--r--fpdfsdk/fpdf_ppo.cpp9
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp6
-rw-r--r--fpdfsdk/pwl/cpwl_appstream.cpp4
-rw-r--r--testing/fuzzers/pdf_codec_jbig2_fuzzer.cc2
19 files changed, 65 insertions, 74 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index e2fa801a58..ea1a1956ae 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -176,7 +176,7 @@ void CPDF_PageContentGenerator::UpdateContentStreams(
if (buf->tellp() <= 0)
page_content_manager.ScheduleRemoveStreamByIndex(stream_index);
else
- old_stream->SetData(buf);
+ old_stream->SetDataFromStringstream(buf);
}
page_content_manager.ExecuteScheduledRemovals();
diff --git a/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp b/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
index b635144b36..b3fe4ae39a 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
@@ -60,7 +60,7 @@ CPDF_Stream* CPDF_PageContentManager::GetStreamByIndex(size_t stream_index) {
size_t CPDF_PageContentManager::AddStream(std::ostringstream* buf) {
CPDF_Stream* new_stream = doc_->NewIndirect<CPDF_Stream>();
- new_stream->SetData(buf);
+ new_stream->SetDataFromStringstream(buf);
// If there is one Content stream (not in an array), now there will be two, so
// create an array with the old and the new one. The new one's index is 1.
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index a8b593682b..a1be407dfe 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -155,7 +155,7 @@ void CPDF_Image::SetJpegImageInline(
if (!pDict)
return;
- m_pStream->InitStream(&(data[0]), size, std::move(pDict));
+ m_pStream->InitStream(data, std::move(pDict));
}
void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
@@ -316,7 +316,7 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
if (!m_pStream)
m_pStream = pdfium::MakeUnique<CPDF_Stream>();
- m_pStream->InitStream(dest_buf, dest_size, std::move(pDict));
+ m_pStream->InitStream({dest_buf, dest_size}, std::move(pDict));
m_bIsMask = pBitmap->IsAlphaMask();
m_Width = BitmapWidth;
m_Height = BitmapHeight;
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
index 30d5dc03ff..4f77bc903b 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
@@ -329,7 +329,7 @@ std::unique_ptr<CPDF_Object> CPDF_CryptoHandler::DecryptObjectTree(
stream_access->LoadAllDataRaw();
if (IsCipherAES() && stream_access->GetSize() < 16) {
- stream->SetData(nullptr, 0);
+ stream->SetData({});
continue;
}
@@ -348,7 +348,7 @@ std::unique_ptr<CPDF_Object> CPDF_CryptoHandler::DecryptObjectTree(
stream->SetData(decrypted_buf.DetachBuffer(), decrypted_size);
} else {
// Decryption failed, set the stream to empty
- stream->SetData(nullptr, 0);
+ stream->SetData({});
}
}
}
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 78a0af7299..768ce98265 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -803,8 +803,7 @@ TEST(PDFArrayTest, ConvertIndirect) {
TEST(PDFStreamTest, SetData) {
std::vector<uint8_t> data(100);
auto stream = pdfium::MakeUnique<CPDF_Stream>();
- stream->InitStream(data.data(), data.size(),
- pdfium::MakeUnique<CPDF_Dictionary>());
+ stream->InitStream(data, pdfium::MakeUnique<CPDF_Dictionary>());
EXPECT_EQ(static_cast<int>(data.size()),
stream->GetDict()->GetIntegerFor(pdfium::stream::kLength));
@@ -814,7 +813,7 @@ TEST(PDFStreamTest, SetData) {
L"SomeParams");
std::vector<uint8_t> new_data(data.size() * 2);
- stream->SetData(new_data.data(), new_data.size());
+ stream->SetData(new_data);
// The "Length" field should be updated for new data size.
EXPECT_EQ(static_cast<int>(new_data.size()),
@@ -830,8 +829,7 @@ TEST(PDFStreamTest, SetData) {
TEST(PDFStreamTest, SetDataAndRemoveFilter) {
std::vector<uint8_t> data(100);
auto stream = pdfium::MakeUnique<CPDF_Stream>();
- stream->InitStream(data.data(), data.size(),
- pdfium::MakeUnique<CPDF_Dictionary>());
+ stream->InitStream(data, pdfium::MakeUnique<CPDF_Dictionary>());
EXPECT_EQ(static_cast<int>(data.size()),
stream->GetDict()->GetIntegerFor(pdfium::stream::kLength));
@@ -841,7 +839,7 @@ TEST(PDFStreamTest, SetDataAndRemoveFilter) {
L"SomeParams");
std::vector<uint8_t> new_data(data.size() * 2);
- stream->SetDataAndRemoveFilter(new_data.data(), new_data.size());
+ stream->SetDataAndRemoveFilter(new_data);
// The "Length" field should be updated for new data size.
EXPECT_EQ(static_cast<int>(new_data.size()),
stream->GetDict()->GetIntegerFor(pdfium::stream::kLength));
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index 64478996a8..81d0e840c0 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -69,11 +69,10 @@ const CPDF_Stream* CPDF_Stream::AsStream() const {
return this;
}
-void CPDF_Stream::InitStream(const uint8_t* pData,
- uint32_t size,
+void CPDF_Stream::InitStream(pdfium::span<const uint8_t> pData,
std::unique_ptr<CPDF_Dictionary> pDict) {
m_pDict = std::move(pDict);
- SetData(pData, size);
+ SetData(pData);
}
void CPDF_Stream::InitStreamFromFile(
@@ -111,29 +110,31 @@ std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic(
std::move(pNewDict));
}
-void CPDF_Stream::SetDataAndRemoveFilter(const uint8_t* pData, uint32_t size) {
- SetData(pData, size);
+void CPDF_Stream::SetDataAndRemoveFilter(pdfium::span<const uint8_t> pData) {
+ SetData(pData);
m_pDict->RemoveFor("Filter");
m_pDict->RemoveFor(pdfium::stream::kDecodeParms);
}
-void CPDF_Stream::SetDataAndRemoveFilter(std::ostringstream* stream) {
+void CPDF_Stream::SetDataFromStringstreamAndRemoveFilter(
+ std::ostringstream* stream) {
if (stream->tellp() <= 0) {
- SetDataAndRemoveFilter(nullptr, 0);
+ SetDataAndRemoveFilter({});
return;
}
SetDataAndRemoveFilter(
- reinterpret_cast<const uint8_t*>(stream->str().c_str()), stream->tellp());
+ {reinterpret_cast<const uint8_t*>(stream->str().c_str()),
+ static_cast<size_t>(stream->tellp())});
}
-void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) {
+void CPDF_Stream::SetData(pdfium::span<const uint8_t> pData) {
std::unique_ptr<uint8_t, FxFreeDeleter> data_copy;
- if (pData) {
- data_copy.reset(FX_Alloc(uint8_t, size));
- memcpy(data_copy.get(), pData, size);
+ if (!pData.empty()) {
+ data_copy.reset(FX_Alloc(uint8_t, pData.size()));
+ memcpy(data_copy.get(), pData.data(), pData.size());
}
- SetData(std::move(data_copy), size);
+ SetData(std::move(data_copy), pData.size());
}
void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
@@ -147,14 +148,13 @@ void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size));
}
-void CPDF_Stream::SetData(std::ostringstream* stream) {
+void CPDF_Stream::SetDataFromStringstream(std::ostringstream* stream) {
if (stream->tellp() <= 0) {
- SetData(nullptr, 0);
+ SetData({});
return;
}
-
- SetData(reinterpret_cast<const uint8_t*>(stream->str().c_str()),
- stream->tellp());
+ SetData({reinterpret_cast<const uint8_t*>(stream->str().c_str()),
+ static_cast<size_t>(stream->tellp())});
}
bool CPDF_Stream::ReadRawData(FX_FILESIZE offset,
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h
index 4a5ac61011..3deb9cddec 100644
--- a/core/fpdfapi/parser/cpdf_stream.h
+++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -18,7 +18,6 @@
class CPDF_Stream : public CPDF_Object {
public:
CPDF_Stream();
-
CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
uint32_t size,
std::unique_ptr<CPDF_Dictionary> pDict);
@@ -42,17 +41,16 @@ class CPDF_Stream : public CPDF_Object {
// Use CPDF_StreamAcc to data access in all cases.
uint8_t* GetInMemoryRawData() const { return m_pDataBuf.get(); }
- // Does not takes ownership of |pData|, copies into internally-owned buffer.
- void SetData(const uint8_t* pData, uint32_t size);
+ // Copies span into internally-owned buffer.
+ void SetData(pdfium::span<const uint8_t> pData);
void SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size);
- void SetData(std::ostringstream* stream);
+ void SetDataFromStringstream(std::ostringstream* stream);
// Set data and remove "Filter" and "DecodeParms" fields from stream
// dictionary.
- void SetDataAndRemoveFilter(const uint8_t* pData, uint32_t size);
- void SetDataAndRemoveFilter(std::ostringstream* stream);
+ void SetDataAndRemoveFilter(pdfium::span<const uint8_t> pData);
+ void SetDataFromStringstreamAndRemoveFilter(std::ostringstream* stream);
- void InitStream(const uint8_t* pData,
- uint32_t size,
+ void InitStream(pdfium::span<const uint8_t> pData,
std::unique_ptr<CPDF_Dictionary> pDict);
void InitStreamFromFile(const RetainPtr<IFX_SeekableReadStream>& pFile,
std::unique_ptr<CPDF_Dictionary> pDict);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 89bf991cd4..65a8d78b13 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -708,8 +708,7 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
pStream->InitStreamFromFile(data, std::move(pDict));
} else {
DCHECK(!len);
- // Empty stream
- pStream->InitStream(nullptr, 0, std::move(pDict));
+ pStream->InitStream({}, std::move(pDict)); // Empty stream
}
const FX_FILESIZE end_stream_offset = GetPos();
memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1);
diff --git a/core/fpdfdoc/cpdf_metadata_unittest.cpp b/core/fpdfdoc/cpdf_metadata_unittest.cpp
index 1a39948461..ed97b4f5bf 100644
--- a/core/fpdfdoc/cpdf_metadata_unittest.cpp
+++ b/core/fpdfdoc/cpdf_metadata_unittest.cpp
@@ -17,7 +17,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormEmailAtTopLevel) {
"</node>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -34,7 +34,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormAcrobatAtTopLevel) {
"</node>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -51,7 +51,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormFilesystemAtTopLevel) {
"</node>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -68,7 +68,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormWithoutWorkflow) {
"</node>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -86,7 +86,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormAsChild) {
"</parent></grandparent>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -100,7 +100,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormAsNoAdhoc) {
"<node></node>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -116,7 +116,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormWrongNamespace) {
"</node>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
@@ -146,7 +146,7 @@ TEST(CPDF_MetadataTest, CheckSharedFormMultipleErrors) {
"</grandparent>";
CPDF_Stream stream;
- stream.SetData(reinterpret_cast<const uint8_t*>(data), strlen(data));
+ stream.SetData(ByteStringView(data).span());
CPDF_Metadata metadata(&stream);
auto results = metadata.CheckForSharedForm();
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 7faa4bfeca..dc2f22d0e6 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -504,7 +504,7 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
std::unique_ptr<CPDF_Dictionary> pResourceDict,
bool bIsTextMarkupAnnotation) {
CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>();
- pNormalStream->SetData(psAppStream);
+ pNormalStream->SetDataFromStringstream(psAppStream);
CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP");
if (!pAPDict)
@@ -1300,7 +1300,7 @@ void CPVT_GenerateAP::GenerateFormAP(Type type,
}
if (pNormalStream) {
- pNormalStream->SetDataAndRemoveFilter(&sAppStream);
+ pNormalStream->SetDataFromStringstreamAndRemoveFilter(&sAppStream);
pStreamDict = pNormalStream->GetDict();
if (pStreamDict) {
pStreamDict->SetMatrixFor("Matrix", matrix);
diff --git a/core/fxcrt/cfx_seekablemultistream_unittest.cpp b/core/fxcrt/cfx_seekablemultistream_unittest.cpp
index 89be1bd180..8d459e8862 100644
--- a/core/fxcrt/cfx_seekablemultistream_unittest.cpp
+++ b/core/fxcrt/cfx_seekablemultistream_unittest.cpp
@@ -43,11 +43,11 @@ TEST(CXFAFileReadTest, NormalStreams) {
auto stream3 = pdfium::MakeUnique<CPDF_Stream>();
// 16 chars total.
- stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5,
+ stream1->InitStream(ByteStringView("one t").span(),
pdfium::MakeUnique<CPDF_Dictionary>());
- stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3,
+ stream2->InitStream(ByteStringView("wo ").span(),
pdfium::MakeUnique<CPDF_Dictionary>());
- stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8,
+ stream3->InitStream(ByteStringView("three!!!").span(),
pdfium::MakeUnique<CPDF_Dictionary>());
streams.push_back(stream1.get());
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index 577f1e0638..2c549d8c90 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -168,7 +168,7 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
auto pOwnedDict =
pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
pStreamDict = pOwnedDict.get();
- pStream->InitStream(nullptr, 0, std::move(pOwnedDict));
+ pStream->InitStream({}, std::move(pOwnedDict));
}
CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 070a7fd78e..b20e5c87dc 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -153,7 +153,7 @@ void UpdateContentStream(CPDF_Form* pForm, CPDF_Stream* pStream) {
CPDF_PageContentGenerator generator(pForm);
std::ostringstream buf;
generator.ProcessPageObjects(&buf);
- pStream->SetDataAndRemoveFilter(&buf);
+ pStream->SetDataFromStringstreamAndRemoveFilter(&buf);
}
void SetQuadPointsAtIndex(CPDF_Array* array,
@@ -784,7 +784,7 @@ FPDFAnnot_SetAP(FPDF_ANNOTATION annot,
ByteString newValue = CFXByteStringFromFPDFWideString(value);
auto pNewApStream = pdfium::MakeUnique<CPDF_Stream>();
- pNewApStream->SetData(newValue.raw_str(), newValue.GetLength());
+ pNewApStream->SetData(newValue.AsRawSpan());
pApDict->SetFor(modeKey, std::move(pNewApStream));
} else {
if (pApDict) {
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 2773763b9a..4dc293be8a 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -94,7 +94,7 @@ CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc,
pFontDesc->SetNewFor<CPDF_Number>("StemV", pFont->IsBold() ? 120 : 70);
CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>();
- pStream->SetData(data, size);
+ pStream->SetData({data, size});
// TODO(npm): Lengths for Type1 fonts.
if (font_type == FPDF_FONT_TRUETYPE) {
pStream->GetDict()->SetNewFor<CPDF_Number>("Length1",
@@ -256,7 +256,7 @@ CPDF_Stream* LoadUnicode(CPDF_Document* pDoc,
buffer << ToUnicodeEnd;
// TODO(npm): Encrypt / Compress?
CPDF_Stream* stream = pDoc->NewIndirect<CPDF_Stream>();
- stream->SetData(&buffer);
+ stream->SetDataFromStringstream(&buffer);
return stream;
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index b9e29be8b4..7ea49cfddf 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -176,7 +176,7 @@ CPDF_Object* NewIndirectContentsStream(const ByteString& key,
pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool()));
ByteString sStream =
ByteString::Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
- pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
+ pNewContents->SetData(sStream.AsRawSpan());
return pNewContents;
}
@@ -205,8 +205,7 @@ void SetPageContents(const ByteString& key,
ByteString sStream = "q\n";
ByteString sBody = ByteString(pAcc->GetData(), pAcc->GetSize());
sStream = sStream + sBody + "\nQ";
- pContentsStream->SetDataAndRemoveFilter(sStream.raw_str(),
- sStream.GetLength());
+ pContentsStream->SetDataAndRemoveFilter(sStream.AsRawSpan());
pContentsArray->Add(pContentsStream->MakeReference(pDocument));
pPage->SetFor(pdfium::page_object::kContents,
pContentsArray->MakeReference(pDocument));
@@ -394,7 +393,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
sStream += ByteString::Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d,
m.e, m.f, sFormName.c_str());
- pNewXObject->SetDataAndRemoveFilter(sStream.raw_str(), sStream.GetLength());
+ pNewXObject->SetDataAndRemoveFilter(sStream.AsRawSpan());
}
pPageDict->RemoveFor("Annots");
return FLATTEN_SUCCESS;
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 722070547f..3c99304a98 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -715,17 +715,14 @@ uint32_t CPDF_NPageToOneExporter::MakeXObject(
bsSrcContentStream += bsStream;
bsSrcContentStream += "\n";
}
- pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.raw_str(),
- bsSrcContentStream.GetLength());
+ pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.AsRawSpan());
} else {
const CPDF_Stream* pStream = pSrcContentObj->AsStream();
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
pAcc->LoadAllDataFiltered();
ByteString bsStream(pAcc->GetData(), pAcc->GetSize());
- pNewXObject->SetDataAndRemoveFilter(bsStream.raw_str(),
- bsStream.GetLength());
+ pNewXObject->SetDataAndRemoveFilter(bsStream.AsRawSpan());
}
-
return pNewXObject->GetObjNum();
}
@@ -752,7 +749,7 @@ void CPDF_NPageToOneExporter::FinishPage(
auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(dest()->GetByteStringPool());
CPDF_Stream* pStream =
dest()->NewIndirect<CPDF_Stream>(nullptr, 0, std::move(pDict));
- pStream->SetData(bsContent.raw_str(), bsContent.GetLength());
+ pStream->SetData(bsContent.AsRawSpan());
pDestPageDict->SetFor(pdfium::page_object::kContents,
pStream->MakeReference(dest()));
}
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 2458e939d2..52b9fd41df 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -136,12 +136,12 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page,
CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(
nullptr, 0,
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
- pStream->SetData(&textBuf);
+ pStream->SetDataFromStringstream(&textBuf);
CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(
nullptr, 0,
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
- pEndStream->SetData((const uint8_t*)" Q", 2);
+ pEndStream->SetData(ByteStringView(" Q").span());
if (CPDF_Array* pContentArray = ToArray(pContentObj)) {
pContentArray->InsertAt(0, pStream->MakeReference(pDoc));
@@ -295,7 +295,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page,
CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(
nullptr, 0,
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
- pStream->SetData(&strClip);
+ pStream->SetDataFromStringstream(&strClip);
if (CPDF_Array* pArray = ToArray(pContentObj)) {
pArray->InsertAt(0, pStream->MakeReference(pDoc));
diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp
index 512af1437a..7d7f710f03 100644
--- a/fpdfsdk/pwl/cpwl_appstream.cpp
+++ b/fpdfsdk/pwl/cpwl_appstream.cpp
@@ -1948,11 +1948,11 @@ void CPWL_AppStream::Write(const ByteString& sAPType,
pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject");
pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form");
pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
- pStream->InitStream(nullptr, 0, std::move(pNewDict));
+ pStream->InitStream({}, std::move(pNewDict));
}
pStreamDict->SetMatrixFor("Matrix", widget_->GetMatrix());
pStreamDict->SetRectFor("BBox", widget_->GetRotatedRect());
- pStream->SetDataAndRemoveFilter(sContents.raw_str(), sContents.GetLength());
+ pStream->SetDataAndRemoveFilter(sContents.AsRawSpan());
}
void CPWL_AppStream::Remove(const ByteString& sAPType) {
diff --git a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
index 7b8e2aac33..8d59760f31 100644
--- a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
@@ -41,7 +41,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return 0;
auto stream = pdfium::MakeUnique<CPDF_Stream>();
- stream->AsStream()->SetData(data, size);
+ stream->AsStream()->SetData({data, size});
auto src_stream = pdfium::MakeRetain<CPDF_StreamAcc>(stream->AsStream());
src_stream->LoadAllDataRaw();