Replace some CPDF_Stream std::unique_ptr ctor usage.

Switch callers that pass in nullptr to a new 1-arg ctor that only takes
a CPDF_Dictionary. This new ctor takes the dictionary but sets the data
to an empty vector.

Change-Id: Id92ba7fee85463ea6858292e9a1821bde06cea02
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/99670
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
index eacad41..1d31cdb 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp
@@ -385,8 +385,8 @@
 TEST_F(CPDF_PageContentGeneratorTest, ProcessEmptyForm) {
   auto pDoc = std::make_unique<CPDF_TestDocument>();
   pDoc->CreateNewDoc();
-  auto pDict = pdfium::MakeRetain<CPDF_Dictionary>();
-  auto pStream = pdfium::MakeRetain<CPDF_Stream>(nullptr, 0, std::move(pDict));
+  auto pStream =
+      pdfium::MakeRetain<CPDF_Stream>(pdfium::MakeRetain<CPDF_Dictionary>());
 
   // Create an empty form.
   auto pTestForm = std::make_unique<CPDF_Form>(pDoc.get(), nullptr, pStream);
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 1c0b1d1..a03a78c 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -960,8 +960,7 @@
   {
     // Create a dictionary/stream pair with a reference loop.
     auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
-    auto stream_obj =
-        dict_obj->SetNewFor<CPDF_Stream>("stream", nullptr, 0, dict_obj);
+    auto stream_obj = dict_obj->SetNewFor<CPDF_Stream>("stream", dict_obj);
     // Clone this object to see whether stack overflow will be triggered.
     RetainPtr<CPDF_Stream> cloned_stream = ToStream(stream_obj->Clone());
     // Cloned object should be the same as the original.
diff --git a/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp b/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp
index 0b8f9da..717b68a 100644
--- a/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_walker_unittest.cpp
@@ -70,8 +70,8 @@
   auto array = pdfium::MakeRetain<CPDF_Array>();
   array->Append(pdfium::MakeRetain<CPDF_Reference>(nullptr, 0));
   array->Append(pdfium::MakeRetain<CPDF_Null>());
-  array->Append(pdfium::MakeRetain<CPDF_Stream>(
-      nullptr, 0, pdfium::MakeRetain<CPDF_Dictionary>()));
+  array->Append(
+      pdfium::MakeRetain<CPDF_Stream>(pdfium::MakeRetain<CPDF_Dictionary>()));
   dict->SetFor("3", std::move(array));
   // The last number for stream length.
   EXPECT_EQ(Walk(dict), "Dict Str Bool Arr Ref Null Stream Dict Num");
@@ -81,8 +81,7 @@
   auto level_4 = pdfium::MakeRetain<CPDF_Number>(0);
   auto level_3 = pdfium::MakeRetain<CPDF_Dictionary>();
   level_3->SetFor("Length", std::move(level_4));
-  auto level_2 =
-      pdfium::MakeRetain<CPDF_Stream>(nullptr, 0, std::move(level_3));
+  auto level_2 = pdfium::MakeRetain<CPDF_Stream>(std::move(level_3));
   auto level_1 = pdfium::MakeRetain<CPDF_Array>();
   level_1->Append(std::move(level_2));
   auto level_0 = pdfium::MakeRetain<CPDF_Dictionary>();
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index 4f7a809..da7eb88 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -38,6 +38,9 @@
 
 CPDF_Stream::CPDF_Stream() = default;
 
+CPDF_Stream::CPDF_Stream(RetainPtr<CPDF_Dictionary> pDict)
+    : CPDF_Stream(DataVector<uint8_t>(), std::move(pDict)) {}
+
 CPDF_Stream::CPDF_Stream(pdfium::span<const uint8_t> pData,
                          RetainPtr<CPDF_Dictionary> pDict)
     : dict_(std::move(pDict)) {
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h
index 812d4ae..a1dc905 100644
--- a/core/fpdfapi/parser/cpdf_stream.h
+++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -67,9 +67,16 @@
   bool HasFilter() const;
 
  private:
+  // Uninitialized.
   CPDF_Stream();
+
+  // Initializes with empty data.
+  explicit CPDF_Stream(RetainPtr<CPDF_Dictionary> pDict);
+
+  // Copies `pData`.
   CPDF_Stream(pdfium::span<const uint8_t> pData,
               RetainPtr<CPDF_Dictionary> pDict);
+
   CPDF_Stream(DataVector<uint8_t> pData, RetainPtr<CPDF_Dictionary> pDict);
   // TODO(crbug.com/pdfium/1872): Replace with vector version above.
   CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
diff --git a/core/fxge/dib/cstretchengine_unittest.cpp b/core/fxge/dib/cstretchengine_unittest.cpp
index 7308410..a3ff6f6 100644
--- a/core/fxge/dib/cstretchengine_unittest.cpp
+++ b/core/fxge/dib/cstretchengine_unittest.cpp
@@ -74,7 +74,7 @@
   dict_obj->SetNewFor<CPDF_Number>("Width", 71000);
   dict_obj->SetNewFor<CPDF_Number>("Height", 12500);
   RetainPtr<CPDF_Stream> stream =
-      pdfium::MakeRetain<CPDF_Stream>(nullptr, 0, std::move(dict_obj));
+      pdfium::MakeRetain<CPDF_Stream>(std::move(dict_obj));
   auto dib_source = pdfium::MakeRetain<CPDF_DIB>(nullptr, stream);
   dib_source->Load();
   CStretchEngine engine(nullptr, FXDIB_Format::k8bppRgb, 500, 500, clip_rect,
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 025545b..374ca10 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -183,8 +183,8 @@
 RetainPtr<CPDF_Reference> NewIndirectContentsStreamReference(
     CPDF_Document* pDocument,
     const ByteString& contents) {
-  auto pNewContents = pDocument->NewIndirect<CPDF_Stream>(
-      nullptr, 0, pDocument->New<CPDF_Dictionary>());
+  auto pNewContents =
+      pDocument->NewIndirect<CPDF_Stream>(pDocument->New<CPDF_Dictionary>());
   pNewContents->SetData(contents.raw_span());
   return pNewContents->MakeReference(pDocument);
 }
@@ -295,8 +295,8 @@
 
   RetainPtr<CPDF_Dictionary> pRes =
       pPageDict->GetOrCreateDictFor(pdfium::page_object::kResources);
-  auto pNewXObject = pDocument->NewIndirect<CPDF_Stream>(
-      nullptr, 0, pDocument->New<CPDF_Dictionary>());
+  auto pNewXObject =
+      pDocument->NewIndirect<CPDF_Stream>(pDocument->New<CPDF_Dictionary>());
   RetainPtr<CPDF_Dictionary> pPageXObject = pRes->GetOrCreateDictFor("XObject");
 
   ByteString key;
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index d29857a..7f7a1fc 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -605,8 +605,8 @@
   RetainPtr<const CPDF_Object> pSrcContentObj =
       pSrcPageDict->GetDirectObjectFor(pdfium::page_object::kContents);
 
-  auto pNewXObject = dest()->NewIndirect<CPDF_Stream>(
-      nullptr, 0, dest()->New<CPDF_Dictionary>());
+  auto pNewXObject =
+      dest()->NewIndirect<CPDF_Stream>(dest()->New<CPDF_Dictionary>());
   RetainPtr<CPDF_Dictionary> pNewXObjectDict = pNewXObject->GetMutableDict();
   static const char kResourceString[] = "Resources";
   if (!CopyInheritable(pNewXObjectDict, pSrcPageDict, kResourceString)) {
@@ -679,8 +679,8 @@
   for (auto& it : m_XObjectNameToNumberMap)
     pPageXObject->SetNewFor<CPDF_Reference>(it.first, dest(), it.second);
 
-  auto pDict = dest()->New<CPDF_Dictionary>();
-  auto pStream = dest()->NewIndirect<CPDF_Stream>(nullptr, 0, std::move(pDict));
+  auto pStream =
+      dest()->NewIndirect<CPDF_Stream>(dest()->New<CPDF_Dictionary>());
   pStream->SetData(bsContent.raw_span());
   pDestPageDict->SetNewFor<CPDF_Reference>(pdfium::page_object::kContents,
                                            dest(), pStream->GetObjNum());
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 4d48f39..4ab1c55 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -228,12 +228,11 @@
   if (matrix)
     WriteMatrix(text_buf, CFXMatrixFromFSMatrix(*matrix)) << " cm ";
 
-  auto pStream =
-      pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>());
+  auto pStream = pDoc->NewIndirect<CPDF_Stream>(pDoc->New<CPDF_Dictionary>());
   pStream->SetDataFromStringstream(&text_buf);
 
   auto pEndStream =
-      pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>());
+      pDoc->NewIndirect<CPDF_Stream>(pDoc->New<CPDF_Dictionary>());
   pEndStream->SetData(ByteStringView(" Q").raw_span());
 
   RetainPtr<CPDF_Array> pContentArray = ToArray(pContentObj);
@@ -406,8 +405,7 @@
   if (!pDoc)
     return;
 
-  auto pStream =
-      pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>());
+  auto pStream = pDoc->NewIndirect<CPDF_Stream>(pDoc->New<CPDF_Dictionary>());
   pStream->SetDataFromStringstream(&strClip);
 
   RetainPtr<CPDF_Array> pArray = ToArray(pContentObj);