summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-16 19:01:27 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-16 19:01:27 +0000
commit08a027cba39d5cb28dafd4280f1ad00c030f1ebf (patch)
treefd229e96e0d87f70dc8df58d5123e29eb9454bce /core
parentad729d325e06fb774637141541f3b5f2ab84c1a6 (diff)
downloadpdfium-08a027cba39d5cb28dafd4280f1ad00c030f1ebf.tar.xz
Consolidate BlackPoint parsing code in CPDF_ColorSpace.
Validate the values as well. Change-Id: I9c87ae9f67650f1f384b3e8a6ca80ea2f411fe50 Reviewed-on: https://pdfium-review.googlesource.com/30796 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 8db74d529d..593176bfbb 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -73,6 +73,29 @@ const uint8_t g_sRGBSamples2[] = {
constexpr size_t kBlackWhitePointCount = 3;
+void GetDefaultBlackPoint(float* pPoints) {
+ static constexpr float kDefaultValue = 0.0f;
+ for (size_t i = 0; i < kBlackWhitePointCount; ++i)
+ pPoints[i] = kDefaultValue;
+}
+
+void GetBlackPoint(const CPDF_Dictionary* pDict, float* pPoints) {
+ const CPDF_Array* pParam = pDict->GetArrayFor("BlackPoint");
+ if (!pParam || pParam->GetCount() != kBlackWhitePointCount) {
+ GetDefaultBlackPoint(pPoints);
+ return;
+ }
+
+ // Check to make sure all values are non-negative.
+ for (size_t i = 0; i < kBlackWhitePointCount; ++i) {
+ pPoints[i] = pParam->GetNumberAt(i);
+ if (pPoints[i] < 0) {
+ GetDefaultBlackPoint(pPoints);
+ return;
+ }
+ }
+}
+
class CPDF_CalGray : public CPDF_ColorSpace {
public:
explicit CPDF_CalGray(CPDF_Document* pDoc);
@@ -588,9 +611,7 @@ uint32_t CPDF_CalGray::v_Load(CPDF_Document* pDoc,
for (size_t i = 0; i < kBlackWhitePointCount; ++i)
m_WhitePoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
- pParam = pDict->GetArrayFor("BlackPoint");
- for (size_t i = 0; i < kBlackWhitePointCount; ++i)
- m_BlackPoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
+ GetBlackPoint(pDict, m_BlackPoint);
m_Gamma = pDict->GetNumberFor("Gamma");
if (m_Gamma == 0)
@@ -635,9 +656,7 @@ uint32_t CPDF_CalRGB::v_Load(CPDF_Document* pDoc,
for (size_t i = 0; i < kBlackWhitePointCount; ++i)
m_WhitePoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
- pParam = pDict->GetArrayFor("BlackPoint");
- for (size_t i = 0; i < kBlackWhitePointCount; ++i)
- m_BlackPoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
+ GetBlackPoint(pDict, m_BlackPoint);
pParam = pDict->GetArrayFor("Gamma");
if (pParam) {
@@ -742,9 +761,7 @@ uint32_t CPDF_LabCS::v_Load(CPDF_Document* pDoc,
for (size_t i = 0; i < kBlackWhitePointCount; ++i)
m_WhitePoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
- pParam = pDict->GetArrayFor("BlackPoint");
- for (size_t i = 0; i < kBlackWhitePointCount; ++i)
- m_BlackPoint[i] = pParam ? pParam->GetNumberAt(i) : 0;
+ GetBlackPoint(pDict, m_BlackPoint);
pParam = pDict->GetArrayFor("Range");
static constexpr float kDefaultRanges[kRangesCount] = {-100.0f, 100.0f,