summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-24 11:07:31 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-24 19:16:51 +0000
commit4a58d1427f8a1b105578f2d27391ceda238ca59c (patch)
tree95d526e6dbe8f37008eed21194190c54b1f7864a
parent73b607fcb5f904893a0610b2c7fb8726d09379e6 (diff)
downloadpdfium-chromium/3052.tar.xz
Refcount CPDF_CMap all the time.chromium/3052chromium/3051
Change-Id: I85ea9529f4188bf818ee96c37944e4546411f79c Reviewed-on: https://pdfium-review.googlesource.com/3211 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.h4
-rw-r--r--core/fpdfapi/font/font_int.h21
-rw-r--r--core/fpdfapi/font/fpdf_font_cid.cpp18
-rw-r--r--testing/libfuzzer/pdf_cmap_fuzzer.cc5
5 files changed, 26 insertions, 24 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 217a6eaf2e..5aad5194cd 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -365,9 +365,9 @@ bool CPDF_CIDFont::Load() {
if (!m_pCMap)
return false;
} else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
- m_pCMap = pdfium::MakeUnique<CPDF_CMap>();
CPDF_StreamAcc acc;
acc.LoadAllData(pStream, false);
+ m_pCMap = pdfium::MakeRetain<CPDF_CMap>();
m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
} else {
return false;
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h
index ec7da6a9bf..938b537b1b 100644
--- a/core/fpdfapi/font/cpdf_cidfont.h
+++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -11,7 +11,7 @@
#include <vector>
#include "core/fpdfapi/font/cpdf_font.h"
-#include "core/fxcrt/cfx_maybe_owned.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -72,7 +72,7 @@ class CPDF_CIDFont : public CPDF_Font {
void LoadSubstFont();
wchar_t GetUnicodeFromCharCode(uint32_t charcode) const;
- CFX_MaybeOwned<CPDF_CMap> m_pCMap;
+ CFX_RetainPtr<CPDF_CMap> m_pCMap;
CPDF_CID2UnicodeMap* m_pCID2UnicodeMap;
CIDSet m_Charset;
bool m_bType1;
diff --git a/core/fpdfapi/font/font_int.h b/core/fpdfapi/font/font_int.h
index 23513d4e90..926ea91a9e 100644
--- a/core/fpdfapi/font/font_int.h
+++ b/core/fpdfapi/font/font_int.h
@@ -12,7 +12,7 @@
#include <vector>
#include "core/fpdfapi/font/cpdf_cidfont.h"
-#include "core/fxcrt/cfx_maybe_owned.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
class CPDF_CID2UnicodeMap;
@@ -31,17 +31,17 @@ class CPDF_CMapManager {
CPDF_CMapManager();
~CPDF_CMapManager();
- CFX_MaybeOwned<CPDF_CMap> GetPredefinedCMap(const CFX_ByteString& name,
- bool bPromptCJK);
+ CFX_RetainPtr<CPDF_CMap> GetPredefinedCMap(const CFX_ByteString& name,
+ bool bPromptCJK);
CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset, bool bPromptCJK);
private:
- std::unique_ptr<CPDF_CMap> LoadPredefinedCMap(const CFX_ByteString& name,
- bool bPromptCJK);
+ CFX_RetainPtr<CPDF_CMap> LoadPredefinedCMap(const CFX_ByteString& name,
+ bool bPromptCJK);
std::unique_ptr<CPDF_CID2UnicodeMap> LoadCID2UnicodeMap(CIDSet charset,
bool bPromptCJK);
- std::map<CFX_ByteString, std::unique_ptr<CPDF_CMap>> m_CMaps;
+ std::map<CFX_ByteString, CFX_RetainPtr<CPDF_CMap>> m_CMaps;
std::unique_ptr<CPDF_CID2UnicodeMap> m_CID2UnicodeMaps[6];
};
@@ -127,7 +127,7 @@ enum CIDCoding : uint8_t {
CIDCODING_UTF16,
};
-class CPDF_CMap {
+class CPDF_CMap : public CFX_Retainable {
public:
enum CodingScheme : uint8_t {
OneByte,
@@ -136,8 +136,8 @@ class CPDF_CMap {
MixedFourBytes
};
- CPDF_CMap();
- ~CPDF_CMap();
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
void LoadPredefined(CPDF_CMapManager* pMgr,
const CFX_ByteString& name,
@@ -156,6 +156,9 @@ class CPDF_CMap {
friend class CPDF_CMapParser;
friend class CPDF_CIDFont;
+ CPDF_CMap();
+ ~CPDF_CMap() override;
+
CFX_ByteString m_PredefinedCMap;
bool m_bVertical;
CIDSet m_Charset;
diff --git a/core/fpdfapi/font/fpdf_font_cid.cpp b/core/fpdfapi/font/fpdf_font_cid.cpp
index e6be712a13..ddc0c12b7d 100644
--- a/core/fpdfapi/font/fpdf_font_cid.cpp
+++ b/core/fpdfapi/font/fpdf_font_cid.cpp
@@ -286,30 +286,28 @@ CPDF_CMapManager::CPDF_CMapManager() {}
CPDF_CMapManager::~CPDF_CMapManager() {}
-CFX_MaybeOwned<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(
+CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(
const CFX_ByteString& name,
bool bPromptCJK) {
auto it = m_CMaps.find(name);
if (it != m_CMaps.end())
- return CFX_MaybeOwned<CPDF_CMap>(it->second.get()); // Unowned.
+ return it->second;
- std::unique_ptr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK);
- if (name.IsEmpty())
- return CFX_MaybeOwned<CPDF_CMap>(std::move(pCMap)); // Owned.
+ CFX_RetainPtr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK);
+ if (!name.IsEmpty())
+ m_CMaps[name] = pCMap;
- CPDF_CMap* pUnowned = pCMap.get();
- m_CMaps[name] = std::move(pCMap);
- return CFX_MaybeOwned<CPDF_CMap>(pUnowned); // Unowned.
+ return pCMap;
}
-std::unique_ptr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(
+CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(
const CFX_ByteString& name,
bool bPromptCJK) {
- auto pCMap = pdfium::MakeUnique<CPDF_CMap>();
const char* pname = name.c_str();
if (*pname == '/')
pname++;
+ auto pCMap = pdfium::MakeRetain<CPDF_CMap>();
pCMap->LoadPredefined(this, pname, bPromptCJK);
return pCMap;
}
diff --git a/testing/libfuzzer/pdf_cmap_fuzzer.cc b/testing/libfuzzer/pdf_cmap_fuzzer.cc
index 1e1ade7e19..ef0f684212 100644
--- a/testing/libfuzzer/pdf_cmap_fuzzer.cc
+++ b/testing/libfuzzer/pdf_cmap_fuzzer.cc
@@ -5,9 +5,10 @@
#include <cstdint>
#include "core/fpdfapi/font/font_int.h"
+#include "third_party/base/ptr_util.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- CPDF_CMap cmap;
- cmap.LoadEmbedded(data, size);
+ auto cmap = pdfium::MakeRetain<CPDF_CMap>();
+ cmap->LoadEmbedded(data, size);
return 0;
}