summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-08-31 12:36:31 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-08-31 20:32:45 +0000
commit0733a1b6a1c3f1d2907f85e823b1b9674322d97b (patch)
treee060e9f2d3065819c22e47e904c30d3ef2633431
parenta864419a26164350a27ff03f34fa30d0166bc077 (diff)
downloadpdfium-0733a1b6a1c3f1d2907f85e823b1b9674322d97b.tar.xz
Change FPDFImageObj_GetImageFilter() to return byte strings.
Since the returned data is a key, it should be a byte string and not a wide string. Change-Id: I9243d88586ea5b13c4b6556479d17316bf07e32e Reviewed-on: https://pdfium-review.googlesource.com/12710 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp24
-rw-r--r--fpdfsdk/fpdfeditimg.cpp11
-rw-r--r--public/fpdf_edit.h2
3 files changed, 20 insertions, 17 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 6dc177e2b5..71933fea43 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -1056,10 +1056,10 @@ TEST_F(FPDFEditEmbeddertest, GetImageFilters) {
ASSERT_EQ(1, FPDFImageObj_GetImageFilterCount(obj));
unsigned long len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0);
std::vector<char> buf(len);
- EXPECT_EQ(24u, FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len));
- EXPECT_STREQ(L"FlateDecode",
- GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
- .c_str());
+ static constexpr char kFlateDecode[] = "FlateDecode";
+ EXPECT_EQ(sizeof(kFlateDecode),
+ FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len));
+ EXPECT_STREQ(kFlateDecode, buf.data());
EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0));
// Verify all the filters for an image object with a list of filters.
@@ -1069,18 +1069,18 @@ TEST_F(FPDFEditEmbeddertest, GetImageFilters) {
len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(30u, FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len));
- EXPECT_STREQ(L"ASCIIHexDecode",
- GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
- .c_str());
+ static constexpr char kASCIIHexDecode[] = "ASCIIHexDecode";
+ EXPECT_EQ(sizeof(kASCIIHexDecode),
+ FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len));
+ EXPECT_STREQ(kASCIIHexDecode, buf.data());
len = FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(20u, FPDFImageObj_GetImageFilter(obj, 1, buf.data(), len));
- EXPECT_STREQ(L"DCTDecode",
- GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
- .c_str());
+ static constexpr char kDCTDecode[] = "DCTDecode";
+ EXPECT_EQ(sizeof(kDCTDecode),
+ FPDFImageObj_GetImageFilter(obj, 1, buf.data(), len));
+ EXPECT_STREQ(kDCTDecode, buf.data());
UnloadPage(page);
}
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index 662ad23d76..5e3191635e 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -244,13 +244,16 @@ FPDFImageObj_GetImageFilter(FPDF_PAGEOBJECT image_object,
CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object);
CPDF_Object* pFilter =
pObj->AsImage()->GetImage()->GetDict()->GetDirectObjectFor("Filter");
- CFX_WideString wsFilters;
+ CFX_ByteString bsFilter;
if (pFilter->IsName())
- wsFilters = pFilter->AsName()->GetUnicodeText();
+ bsFilter = pFilter->AsName()->GetString();
else
- wsFilters = pFilter->AsArray()->GetUnicodeTextAt(index);
+ bsFilter = pFilter->AsArray()->GetStringAt(index);
- return Utf16EncodeMaybeCopyAndReturnLength(wsFilters, buffer, buflen);
+ unsigned long len = bsFilter.GetLength() + 1;
+ if (buffer && len <= buflen)
+ memcpy(buffer, bsFilter.c_str(), len);
+ return len;
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index c547f07890..22582674ea 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -385,7 +385,7 @@ FPDFImageObj_GetImageFilterCount(FPDF_PAGEOBJECT image_object);
//
// image_object - handle to an image object.
// index - the index of the filter requested.
-// buffer - buffer for holding filter string, encoded in UTF16-LE.
+// buffer - buffer for holding filter string, encoded in UTF-8.
// buflen - length of the buffer.
//
// Returns the length of the filter string.