Separate Jbig2Module from ModuleMgr.
Just talk to Jbig2Module directly when needed. Make its methods static
now that the class is no longer instantiated.
Change-Id: I4301f6f580e0eb7e0b5312eda516296189ccaecf
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69932
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 50982b5..f3ea222 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -323,8 +323,6 @@
return LoadState::kFail;
FXCODEC_STATUS iDecodeStatus;
- Jbig2Module* pJbig2Module =
- fxcodec::ModuleMgr::GetInstance()->GetJbig2Module();
if (!m_pJbig2Context) {
m_pJbig2Context = pdfium::MakeUnique<Jbig2Context>();
if (m_pStreamAcc->GetImageParam()) {
@@ -349,12 +347,12 @@
if (m_pGlobalAcc->GetStream())
nGlobalObjNum = m_pGlobalAcc->GetStream()->GetObjNum();
}
- iDecodeStatus = pJbig2Module->StartDecode(
+ iDecodeStatus = Jbig2Module::StartDecode(
m_pJbig2Context.get(), m_pDocument->CodecContext(), m_Width, m_Height,
pSrcSpan, nSrcObjNum, pGlobalSpan, nGlobalObjNum,
m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause);
} else {
- iDecodeStatus = pJbig2Module->ContinueDecode(m_pJbig2Context.get(), pPause);
+ iDecodeStatus = Jbig2Module::ContinueDecode(m_pJbig2Context.get(), pPause);
}
if (iDecodeStatus < 0) {
diff --git a/core/fxcodec/fx_codec.cpp b/core/fxcodec/fx_codec.cpp
index 4dcf695..51e8117 100644
--- a/core/fxcodec/fx_codec.cpp
+++ b/core/fxcodec/fx_codec.cpp
@@ -11,7 +11,6 @@
#include <memory>
#include <utility>
-#include "core/fxcodec/jbig2/jbig2module.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/logging.h"
@@ -44,7 +43,7 @@
return g_ModuleMgr;
}
-ModuleMgr::ModuleMgr() : m_pJbig2Module(pdfium::MakeUnique<Jbig2Module>()) {
+ModuleMgr::ModuleMgr() {
#ifdef PDF_ENABLE_XFA_BMP
SetBmpModule(pdfium::MakeUnique<BmpModule>());
#endif
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 7f20475..8ab623a 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -48,7 +48,6 @@
};
#endif // PDF_ENABLE_XFA
-class Jbig2Module;
class ProgressiveDecoder;
class ModuleMgr {
@@ -58,8 +57,6 @@
static void Destroy();
static ModuleMgr* GetInstance();
- Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
-
#ifdef PDF_ENABLE_XFA
std::unique_ptr<ProgressiveDecoder> CreateProgressiveDecoder();
@@ -96,8 +93,6 @@
ModuleMgr();
~ModuleMgr();
- std::unique_ptr<Jbig2Module> m_pJbig2Module;
-
#ifdef PDF_ENABLE_XFA
#ifdef PDF_ENABLE_XFA_BMP
std::unique_ptr<BmpModule> m_pBmpModule;
diff --git a/core/fxcodec/jbig2/jbig2module.cpp b/core/fxcodec/jbig2/jbig2module.cpp
index 2b78814..46413ed 100644
--- a/core/fxcodec/jbig2/jbig2module.cpp
+++ b/core/fxcodec/jbig2/jbig2module.cpp
@@ -12,6 +12,26 @@
namespace fxcodec {
+namespace {
+
+FXCODEC_STATUS Decode(Jbig2Context* pJbig2Context, bool decode_success) {
+ FXCODEC_STATUS status = pJbig2Context->m_pContext->GetProcessingStatus();
+ if (status != FXCODEC_STATUS_DECODE_FINISH)
+ return status;
+
+ pJbig2Context->m_pContext.reset();
+ if (!decode_success)
+ return FXCODEC_STATUS_ERROR;
+
+ int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4;
+ uint32_t* dword_buf = reinterpret_cast<uint32_t*>(pJbig2Context->m_dest_buf);
+ for (int i = 0; i < dword_size; i++)
+ dword_buf[i] = ~dword_buf[i];
+ return FXCODEC_STATUS_DECODE_FINISH;
+}
+
+} // namespace
+
JBig2_DocumentContext* GetJBig2DocumentContext(
std::unique_ptr<JBig2_DocumentContext>* pContextHolder) {
if (!*pContextHolder)
@@ -23,10 +43,7 @@
Jbig2Context::~Jbig2Context() = default;
-Jbig2Module::Jbig2Module() = default;
-
-Jbig2Module::~Jbig2Module() = default;
-
+// static
FXCODEC_STATUS Jbig2Module::StartDecode(
Jbig2Context* pJbig2Context,
std::unique_ptr<JBig2_DocumentContext>* pContextHolder,
@@ -60,27 +77,11 @@
return Decode(pJbig2Context, succeeded);
}
+// static
FXCODEC_STATUS Jbig2Module::ContinueDecode(Jbig2Context* pJbig2Context,
PauseIndicatorIface* pPause) {
bool succeeded = pJbig2Context->m_pContext->Continue(pPause);
return Decode(pJbig2Context, succeeded);
}
-FXCODEC_STATUS Jbig2Module::Decode(Jbig2Context* pJbig2Context,
- bool decode_success) {
- FXCODEC_STATUS status = pJbig2Context->m_pContext->GetProcessingStatus();
- if (status != FXCODEC_STATUS_DECODE_FINISH)
- return status;
-
- pJbig2Context->m_pContext.reset();
- if (!decode_success)
- return FXCODEC_STATUS_ERROR;
-
- int dword_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch / 4;
- uint32_t* dword_buf = reinterpret_cast<uint32_t*>(pJbig2Context->m_dest_buf);
- for (int i = 0; i < dword_size; i++)
- dword_buf[i] = ~dword_buf[i];
- return FXCODEC_STATUS_DECODE_FINISH;
-}
-
} // namespace fxcodec
diff --git a/core/fxcodec/jbig2/jbig2module.h b/core/fxcodec/jbig2/jbig2module.h
index 6f9b0bb..c253a9a 100644
--- a/core/fxcodec/jbig2/jbig2module.h
+++ b/core/fxcodec/jbig2/jbig2module.h
@@ -37,10 +37,7 @@
class Jbig2Module {
public:
- Jbig2Module();
- ~Jbig2Module();
-
- FXCODEC_STATUS StartDecode(
+ static FXCODEC_STATUS StartDecode(
Jbig2Context* pJbig2Context,
std::unique_ptr<JBig2_DocumentContext>* pContextHolder,
uint32_t width,
@@ -53,11 +50,12 @@
uint32_t dest_pitch,
PauseIndicatorIface* pPause);
- FXCODEC_STATUS ContinueDecode(Jbig2Context* pJbig2Context,
- PauseIndicatorIface* pPause);
+ static FXCODEC_STATUS ContinueDecode(Jbig2Context* pJbig2Context,
+ PauseIndicatorIface* pPause);
- private:
- FXCODEC_STATUS Decode(Jbig2Context* pJbig2Context, bool decode_success);
+ Jbig2Module() = delete;
+ Jbig2Module(const Jbig2Module&) = delete;
+ Jbig2Module& operator=(const Jbig2Module&) = delete;
};
} // namespace fxcodec
diff --git a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
index 2878d7c..ac24dfd 100644
--- a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
@@ -35,14 +35,13 @@
if (!bitmap->Create(width, height, FXDIB_1bppRgb))
return 0;
- Jbig2Module module;
Jbig2Context jbig2_context;
std::unique_ptr<JBig2_DocumentContext> document_context;
- FXCODEC_STATUS status = module.StartDecode(
+ FXCODEC_STATUS status = Jbig2Module::StartDecode(
&jbig2_context, &document_context, width, height, {data, size}, 1, {}, 0,
bitmap->GetBuffer(), bitmap->GetPitch(), nullptr);
while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
- status = module.ContinueDecode(&jbig2_context, nullptr);
+ status = Jbig2Module::ContinueDecode(&jbig2_context, nullptr);
return 0;
}