summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-06-06 12:31:18 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-06 12:31:18 +0000
commiteababa10789bc0d73a325291e2854090ee3896cd (patch)
tree67bb315c3e405c622c9fac40f0f473b4ec2b8fc1 /fpdfsdk
parentc22d671728605bc614dc84ec6a42a5647808b30d (diff)
downloadpdfium-eababa10789bc0d73a325291e2854090ee3896cd.tar.xz
Use CPDF_StreamAcc to data access of CPDF_Stream.
Change-Id: I68b88e013ac542f245dbe7b6889799c814d46eb8 Reviewed-on: https://pdfium-review.googlesource.com/33690 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_helpers.cpp43
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp13
-rw-r--r--fpdfsdk/fpdf_editimg.cpp11
3 files changed, 26 insertions, 41 deletions
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index e96b09f3a1..1ceecfe21f 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -11,6 +11,7 @@
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfdoc/cpdf_annot.h"
#include "core/fpdfdoc/cpdf_interform.h"
@@ -319,40 +320,14 @@ unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
void* buffer,
unsigned long buflen) {
ASSERT(stream);
- uint8_t* data = stream->GetRawData();
- uint32_t len = stream->GetRawSize();
- const CPDF_Dictionary* dict = stream->GetDict();
- const CPDF_Object* decoder =
- dict ? dict->GetDirectObjectFor("Filter") : nullptr;
- if (decoder && (decoder->IsArray() || decoder->IsName())) {
- // Decode the stream if one or more stream filters are specified.
- uint8_t* decoded_data = nullptr;
- uint32_t decoded_len = 0;
- ByteString dummy_last_decoder;
- const CPDF_Dictionary* dummy_last_param;
- if (PDF_DataDecode(data, len, dict,
- dict->GetIntegerFor(pdfium::stream::kDL), false,
- &decoded_data, &decoded_len, &dummy_last_decoder,
- &dummy_last_param)) {
- if (buffer && buflen >= decoded_len)
- memcpy(buffer, decoded_data, decoded_len);
-
- // Free the buffer for the decoded data if it was allocated by
- // PDF_DataDecode(). Note that for images with a single image-specific
- // filter, |decoded_data| is directly assigned to be |data|, so
- // |decoded_data| does not need to be freed.
- if (decoded_data != data)
- FX_Free(decoded_data);
-
- return decoded_len;
- }
- }
- // Copy the raw data and return its length if there is no valid filter
- // specified or if decoding failed.
- if (buffer && buflen >= len)
- memcpy(buffer, data, len);
-
- return len;
+ auto stream_acc = pdfium::MakeRetain<CPDF_StreamAcc>(stream);
+ stream_acc->LoadAllDataFiltered();
+ const auto stream_data_size = stream_acc->GetSize();
+ if (!buffer || buflen < stream_data_size)
+ return stream_data_size;
+
+ memcpy(buffer, stream_acc->GetData(), stream_data_size);
+ return stream_data_size;
}
unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text,
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index b2a7c32153..f339a82336 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -13,6 +13,7 @@
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_system.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
#include "public/cpp/fpdf_scopers.h"
@@ -74,14 +75,18 @@ class FPDFEditEmbeddertest : public EmbedderTest {
EXPECT_TRUE(font_desc->KeyExist(present));
EXPECT_FALSE(font_desc->KeyExist(absent));
+ auto streamAcc =
+ pdfium::MakeRetain<CPDF_StreamAcc>(font_desc->GetStreamFor(present));
+ streamAcc->LoadAllDataRaw();
+
// Check that the font stream is the one that was provided
- const CPDF_Stream* font_stream = font_desc->GetStreamFor(present);
- ASSERT_EQ(size, font_stream->GetRawSize());
+ ASSERT_EQ(size, streamAcc->GetSize());
if (font_type == FPDF_FONT_TRUETYPE) {
ASSERT_EQ(static_cast<int>(size),
- font_stream->GetDict()->GetIntegerFor("Length1"));
+ streamAcc->GetDict()->GetIntegerFor("Length1"));
}
- uint8_t* stream_data = font_stream->GetRawData();
+
+ const uint8_t* stream_data = streamAcc->GetData();
for (size_t j = 0; j < size; j++)
EXPECT_EQ(data[j], stream_data[j]) << " at byte " << j;
}
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp
index fed1581e2d..7aa93e98ec 100644
--- a/fpdfsdk/fpdf_editimg.cpp
+++ b/fpdfsdk/fpdf_editimg.cpp
@@ -13,6 +13,7 @@
#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/render/cpdf_dibsource.h"
#include "fpdfsdk/cpdfsdk_customaccess.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
@@ -221,10 +222,14 @@ FPDFImageObj_GetImageDataRaw(FPDF_PAGEOBJECT image_object,
if (!pImgStream)
return 0;
- uint32_t len = pImgStream->GetRawSize();
- if (buffer && buflen >= len)
- memcpy(buffer, pImgStream->GetRawData(), len);
+ auto streamAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pImgStream);
+ streamAcc->LoadAllDataRaw();
+ const uint32_t len = streamAcc->GetSize();
+ if (!buffer || buflen < len)
+ return len;
+
+ memcpy(buffer, streamAcc->GetData(), len);
return len;
}