Get rid of CCodec_ModuleMgr::GetFaxModule().

The CCodec_FaxModule class consists of a set of methods that can all be
static. Make the methods static, and make sure CCodec_FaxModule cannot
be instantiated. Then CCodec_ModuleMgr::GetFaxModule() becomes pointless
and all the callers can just call CCodec_FaxModule directly.

Change-Id: If09629d3e9875f304708337fed17b5a5819cfa7c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55011
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index 5c907d9..fb2194e 100644
--- a/core/fpdfapi/cpdf_modulemgr.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -60,10 +60,6 @@
   LoadCodecModules();
 }
 
-CCodec_FaxModule* CPDF_ModuleMgr::GetFaxModule() {
-  return m_pCodecModule->GetFaxModule();
-}
-
 CCodec_JpegModule* CPDF_ModuleMgr::GetJpegModule() {
   return m_pCodecModule->GetJpegModule();
 }
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h
index 69b4833..d94bce5 100644
--- a/core/fpdfapi/cpdf_modulemgr.h
+++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -10,7 +10,6 @@
 #include <memory>
 #include <utility>
 
-class CCodec_FaxModule;
 class CCodec_FlateModule;
 class CCodec_IccModule;
 class CCodec_Jbig2Module;
@@ -52,7 +51,6 @@
   CCodec_ModuleMgr* GetCodecModule() const { return m_pCodecModule.get(); }
   CPDF_PageModule* GetPageModule() const { return m_pPageModule.get(); }
 
-  CCodec_FaxModule* GetFaxModule();
   CCodec_JpegModule* GetJpegModule();
   CCodec_JpxModule* GetJpxModule();
   CCodec_Jbig2Module* GetJbig2Module();
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 05784df..034f65d 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -313,9 +313,8 @@
     if (Rows > USHRT_MAX)
       Rows = 0;
   }
-  return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder(
-      src_span, width, height, K, EndOfLine, ByteAlign, BlackIs1, Columns,
-      Rows);
+  return CCodec_FaxModule::CreateDecoder(src_span, width, height, K, EndOfLine,
+                                         ByteAlign, BlackIs1, Columns, Rows);
 }
 
 std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder(
diff --git a/core/fxcodec/codec/ccodec_faxmodule.cpp b/core/fxcodec/codec/ccodec_faxmodule.cpp
index 8979826..4079366 100644
--- a/core/fxcodec/codec/ccodec_faxmodule.cpp
+++ b/core/fxcodec/codec/ccodec_faxmodule.cpp
@@ -572,26 +572,6 @@
 }  // namespace
 
 // static
-int CCodec_FaxModule::FaxG4Decode(const uint8_t* src_buf,
-                                  uint32_t src_size,
-                                  int starting_bitpos,
-                                  int width,
-                                  int height,
-                                  int pitch,
-                                  uint8_t* dest_buf) {
-  ASSERT(pitch != 0);
-
-  std::vector<uint8_t> ref_buf(pitch, 0xff);
-  int bitpos = starting_bitpos;
-  for (int iRow = 0; iRow < height; ++iRow) {
-    uint8_t* line_buf = dest_buf + iRow * pitch;
-    memset(line_buf, 0xff, pitch);
-    FaxG4GetRow(src_buf, src_size << 3, &bitpos, line_buf, ref_buf, width);
-    memcpy(ref_buf.data(), line_buf, pitch);
-  }
-  return bitpos;
-}
-
 std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FaxModule::CreateDecoder(
     pdfium::span<const uint8_t> src_span,
     int width,
@@ -618,6 +598,27 @@
                                                EncodedByteAlign, BlackIs1);
 }
 
+// static
+int CCodec_FaxModule::FaxG4Decode(const uint8_t* src_buf,
+                                  uint32_t src_size,
+                                  int starting_bitpos,
+                                  int width,
+                                  int height,
+                                  int pitch,
+                                  uint8_t* dest_buf) {
+  ASSERT(pitch != 0);
+
+  std::vector<uint8_t> ref_buf(pitch, 0xff);
+  int bitpos = starting_bitpos;
+  for (int iRow = 0; iRow < height; ++iRow) {
+    uint8_t* line_buf = dest_buf + iRow * pitch;
+    memset(line_buf, 0xff, pitch);
+    FaxG4GetRow(src_buf, src_size << 3, &bitpos, line_buf, ref_buf, width);
+    memcpy(ref_buf.data(), line_buf, pitch);
+  }
+  return bitpos;
+}
+
 #if defined(OS_WIN)
 namespace {
 const uint8_t BlackRunTerminator[128] = {
@@ -799,6 +800,7 @@
 
 }  // namespace
 
+// static
 void CCodec_FaxModule::FaxEncode(
     const uint8_t* src_buf,
     int width,
diff --git a/core/fxcodec/codec/ccodec_faxmodule.h b/core/fxcodec/codec/ccodec_faxmodule.h
index 608cffa..d2cc07a 100644
--- a/core/fxcodec/codec/ccodec_faxmodule.h
+++ b/core/fxcodec/codec/ccodec_faxmodule.h
@@ -18,7 +18,7 @@
 
 class CCodec_FaxModule {
  public:
-  std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
+  static std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
       pdfium::span<const uint8_t> src_buf,
       int width,
       int height,
@@ -29,6 +29,15 @@
       int Columns,
       int Rows);
 
+  // Return the ending bit position.
+  static int FaxG4Decode(const uint8_t* src_buf,
+                         uint32_t src_size,
+                         int starting_bitpos,
+                         int width,
+                         int height,
+                         int pitch,
+                         uint8_t* dest_buf);
+
 #if defined(OS_WIN)
   static void FaxEncode(const uint8_t* src_buf,
                         int width,
@@ -38,14 +47,9 @@
                         uint32_t* dest_size);
 #endif  // defined(OS_WIN)
 
-  // Return the ending bit position.
-  static int FaxG4Decode(const uint8_t* src_buf,
-                         uint32_t src_size,
-                         int starting_bitpos,
-                         int width,
-                         int height,
-                         int pitch,
-                         uint8_t* dest_buf);
+  CCodec_FaxModule() = delete;
+  CCodec_FaxModule(const CCodec_FaxModule&) = delete;
+  CCodec_FaxModule& operator=(const CCodec_FaxModule&) = delete;
 };
 
 #endif  // CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_
diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp
index e2ba733..37f7a7d 100644
--- a/core/fxcodec/codec/fx_codec.cpp
+++ b/core/fxcodec/codec/fx_codec.cpp
@@ -11,7 +11,6 @@
 #include <memory>
 #include <utility>
 
-#include "core/fxcodec/codec/ccodec_faxmodule.h"
 #include "core/fxcodec/codec/ccodec_iccmodule.h"
 #include "core/fxcodec/codec/ccodec_jbig2module.h"
 #include "core/fxcodec/codec/ccodec_jpegmodule.h"
@@ -23,8 +22,7 @@
 #include "third_party/base/ptr_util.h"
 
 CCodec_ModuleMgr::CCodec_ModuleMgr()
-    : m_pFaxModule(pdfium::MakeUnique<CCodec_FaxModule>()),
-      m_pJpegModule(pdfium::MakeUnique<CCodec_JpegModule>()),
+    : m_pJpegModule(pdfium::MakeUnique<CCodec_JpegModule>()),
       m_pJpxModule(pdfium::MakeUnique<CCodec_JpxModule>()),
       m_pJbig2Module(pdfium::MakeUnique<CCodec_Jbig2Module>()),
       m_pIccModule(pdfium::MakeUnique<CCodec_IccModule>()) {}
@@ -32,7 +30,7 @@
 CCodec_ModuleMgr::~CCodec_ModuleMgr() = default;
 
 #ifdef PDF_ENABLE_XFA
-CFX_DIBAttribute::CFX_DIBAttribute() {}
+CFX_DIBAttribute::CFX_DIBAttribute() = default;
 
 CFX_DIBAttribute::~CFX_DIBAttribute() {
   for (const auto& pair : m_Exif)
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 2ab6fae..e72ac19 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -34,14 +34,10 @@
 #endif  // PDF_ENABLE_XFA_TIFF
 #endif  // PDF_ENABLE_XFA
 
-class CCodec_FaxModule;
 class CCodec_IccModule;
 class CCodec_Jbig2Module;
 class CCodec_JpegModule;
 class CCodec_JpxModule;
-class CFX_DIBBase;
-class CJPX_Decoder;
-class CPDF_ColorSpace;
 
 #ifdef PDF_ENABLE_XFA
 class CCodec_ProgressiveDecoder;
@@ -63,7 +59,6 @@
   CCodec_ModuleMgr();
   ~CCodec_ModuleMgr();
 
-  CCodec_FaxModule* GetFaxModule() const { return m_pFaxModule.get(); }
   CCodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
   CCodec_JpxModule* GetJpxModule() const { return m_pJpxModule.get(); }
   CCodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
@@ -102,7 +97,6 @@
 #endif  // PDF_ENABLE_XFA
 
  protected:
-  std::unique_ptr<CCodec_FaxModule> m_pFaxModule;
   std::unique_ptr<CCodec_JpegModule> m_pJpegModule;
   std::unique_ptr<CCodec_JpxModule> m_pJpxModule;
   std::unique_ptr<CCodec_Jbig2Module> m_pJbig2Module;
diff --git a/testing/fuzzers/pdf_codec_fax_fuzzer.cc b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
index 043860a..c7d44e5 100644
--- a/testing/fuzzers/pdf_codec_fax_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
@@ -32,10 +32,9 @@
   data += kParameterSize;
   size -= kParameterSize;
 
-  CCodec_FaxModule fax_module;
-  std::unique_ptr<CCodec_ScanlineDecoder> decoder(
-      fax_module.CreateDecoder({data, size}, width, height, K, EndOfLine,
-                               ByteAlign, kBlackIs1, Columns, Rows));
+  std::unique_ptr<CCodec_ScanlineDecoder> decoder =
+      CCodec_FaxModule::CreateDecoder({data, size}, width, height, K, EndOfLine,
+                                      ByteAlign, kBlackIs1, Columns, Rows);
 
   if (decoder) {
     int line = 0;