summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-04 14:37:18 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-04 21:48:48 +0000
commitafd0d1f488ea55da545b3310fd8f22e45522a695 (patch)
tree89136eba4669421b6f828edb9f3d69ee558110d0 /core/fxcodec/jbig2
parent4f8b044b95dc282959dfe41453e2a9c1ec7e9354 (diff)
downloadpdfium-afd0d1f488ea55da545b3310fd8f22e45522a695.tar.xz
RefCount CPDF_StreamAcc all the time.
Pass stream argument to constructor; it feels like a stream accessor should always be made from a stream rather than passing one in after the fact. Change-Id: Iaa46cb37677b81f0170f5d39bab76ad38ea4af44 Reviewed-on: https://pdfium-review.googlesource.com/3620 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcodec/jbig2')
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream.cpp3
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream.h3
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp36
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp11
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.h4
5 files changed, 30 insertions, 27 deletions
diff --git a/core/fxcodec/jbig2/JBig2_BitStream.cpp b/core/fxcodec/jbig2/JBig2_BitStream.cpp
index 67d82f49a7..921fa2a661 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream.cpp
+++ b/core/fxcodec/jbig2/JBig2_BitStream.cpp
@@ -11,7 +11,8 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
-CJBig2_BitStream::CJBig2_BitStream(CPDF_StreamAcc* pSrcStream)
+CJBig2_BitStream::CJBig2_BitStream(
+ const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream)
: m_pBuf(pSrcStream->GetData()),
m_dwLength(pSrcStream->GetSize()),
m_dwByteIdx(0),
diff --git a/core/fxcodec/jbig2/JBig2_BitStream.h b/core/fxcodec/jbig2/JBig2_BitStream.h
index 551b7df9b1..7517eb0c6c 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream.h
+++ b/core/fxcodec/jbig2/JBig2_BitStream.h
@@ -7,13 +7,14 @@
#ifndef CORE_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
#define CORE_FXCODEC_JBIG2_JBIG2_BITSTREAM_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
class CPDF_StreamAcc;
class CJBig2_BitStream {
public:
- explicit CJBig2_BitStream(CPDF_StreamAcc* pSrcStream);
+ explicit CJBig2_BitStream(const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream);
~CJBig2_BitStream();
// TODO(thestig): readFoo() should return bool.
diff --git a/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp b/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp
index f9d69b9c53..7b91eff982 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp
+++ b/core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp
@@ -16,10 +16,10 @@ TEST(JBig2_BitStream, ReadNBits) {
data.get()[0] = 0xb1; // 10110001
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 1, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(0, stream.readNBits(1, &val1));
@@ -41,10 +41,10 @@ TEST(JBig2_BitStream, ReadNBitsLargerThenData) {
data.get()[0] = 0xb1;
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 1, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(0, stream.readNBits(10, &val1));
@@ -53,10 +53,10 @@ TEST(JBig2_BitStream, ReadNBitsLargerThenData) {
TEST(JBig2_BitStream, ReadNBitsNullStream) {
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(-1, stream.readNBits(1, &val1));
@@ -69,10 +69,10 @@ TEST(JBig2_BitStream, ReadNBitsEmptyStream) {
std::unique_ptr<uint8_t, FxFreeDeleter> data(FX_Alloc(uint8_t, 1));
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 0, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(-1, stream.readNBits(1, &val1));
@@ -86,10 +86,10 @@ TEST(JBig2_BitStream, ReadNBitsOutOfBounds) {
data.get()[0] = 0xb1; // 10110001
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 1, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
uint32_t val1;
EXPECT_EQ(0, stream.readNBits(8, &val1));
@@ -107,10 +107,10 @@ TEST(JBig2_BitStream, ReadNBitsWhereNIs36) {
data.get()[4] = 0x40;
auto in_stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), 5, nullptr);
- auto acc = pdfium::MakeUnique<CPDF_StreamAcc>();
- acc->LoadAllData(in_stream.get());
+ auto acc = pdfium::MakeRetain<CPDF_StreamAcc>(in_stream.get());
+ acc->LoadAllData();
- CJBig2_BitStream stream(acc.get());
+ CJBig2_BitStream stream(acc);
// This will shift off the top two bits and they end up lost.
uint32_t val1;
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 9261d16bfc..116abb7754 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -46,11 +46,12 @@ size_t GetRefAggContextSize(bool val) {
// difference for typical JBIG2 documents.
static const int kSymbolDictCacheMaxSize = 2;
-CJBig2_Context::CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
- std::list<CJBig2_CachePair>* pSymbolDictCache,
- IFX_Pause* pPause,
- bool bIsGlobal)
+CJBig2_Context::CJBig2_Context(
+ const CFX_RetainPtr<CPDF_StreamAcc>& pGlobalStream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream,
+ std::list<CJBig2_CachePair>* pSymbolDictCache,
+ IFX_Pause* pPause,
+ bool bIsGlobal)
: m_nSegmentDecoded(0),
m_bInPage(false),
m_bBufSpecified(false),
diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h
index cd44a82c61..31865d4d46 100644
--- a/core/fxcodec/jbig2/JBig2_Context.h
+++ b/core/fxcodec/jbig2/JBig2_Context.h
@@ -40,8 +40,8 @@ using CJBig2_CachePair =
class CJBig2_Context {
public:
- CJBig2_Context(CPDF_StreamAcc* pGlobalStream,
- CPDF_StreamAcc* pSrcStream,
+ CJBig2_Context(const CFX_RetainPtr<CPDF_StreamAcc>& pGlobalStream,
+ const CFX_RetainPtr<CPDF_StreamAcc>& pSrcStream,
std::list<CJBig2_CachePair>* pSymbolDictCache,
IFX_Pause* pPause,
bool bIsGlobal);