Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_meshstream.cpp

Issue 2022263003: Validate a couple of fields in shading dictionaries. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_page/cpdf_meshstream.h" 7 #include "core/fpdfapi/fpdf_page/cpdf_meshstream.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_colorspace.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_colorspace.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h" 10 #include "core/fpdfapi/fpdf_page/pageint.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
12 12
13 namespace {
14
15 // See PDF Reference 1.7, page 315, table 4.32. (Also table 4.33 and 4.34)
16 bool IsValidBitsPerComponent(uint32_t x) {
17 switch (x) {
18 case 1:
19 case 2:
20 case 4:
21 case 8:
22 case 12:
23 case 16:
24 return true;
25 default:
26 return false;
27 }
28 }
29
30 // Same references as IsValidBitsPerComponent() above.
31 bool IsValidBitsPerCoordinate(uint32_t x) {
32 switch (x) {
33 case 1:
34 case 2:
35 case 4:
36 case 8:
37 case 12:
38 case 16:
39 case 24:
40 case 32:
41 return true;
42 default:
43 return false;
44 }
45 }
46
47 } // namespace
48
13 CPDF_MeshStream::CPDF_MeshStream( 49 CPDF_MeshStream::CPDF_MeshStream(
14 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, 50 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
15 CPDF_ColorSpace* pCS) 51 CPDF_ColorSpace* pCS)
16 : m_funcs(funcs), m_pCS(pCS) {} 52 : m_funcs(funcs), m_pCS(pCS) {}
17 53
18 bool CPDF_MeshStream::Load(CPDF_Stream* pShadingStream) { 54 bool CPDF_MeshStream::Load(CPDF_Stream* pShadingStream) {
19 m_Stream.LoadAllData(pShadingStream); 55 m_Stream.LoadAllData(pShadingStream);
20 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); 56 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize());
21 CPDF_Dictionary* pDict = pShadingStream->GetDict(); 57 CPDF_Dictionary* pDict = pShadingStream->GetDict();
22 m_nCoordBits = pDict->GetIntegerBy("BitsPerCoordinate"); 58 m_nCoordBits = pDict->GetIntegerBy("BitsPerCoordinate");
59 if (!IsValidBitsPerCoordinate(m_nCoordBits))
60 return false;
61
23 m_nCompBits = pDict->GetIntegerBy("BitsPerComponent"); 62 m_nCompBits = pDict->GetIntegerBy("BitsPerComponent");
63 if (!IsValidBitsPerComponent(m_nCompBits))
64 return false;
65
24 m_nFlagBits = pDict->GetIntegerBy("BitsPerFlag"); 66 m_nFlagBits = pDict->GetIntegerBy("BitsPerFlag");
25 if (!m_nCoordBits || !m_nCompBits)
26 return FALSE;
27
28 uint32_t nComps = m_pCS->CountComponents(); 67 uint32_t nComps = m_pCS->CountComponents();
29 if (nComps > 8) 68 if (nComps > 8)
30 return FALSE; 69 return false;
31 70
32 m_nComps = m_funcs.empty() ? nComps : 1; 71 m_nComps = m_funcs.empty() ? nComps : 1;
33 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; 72 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1;
34 m_CompMax = (1 << m_nCompBits) - 1; 73 m_CompMax = (1 << m_nCompBits) - 1;
35 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); 74 CPDF_Array* pDecode = pDict->GetArrayBy("Decode");
36 if (!pDecode || pDecode->GetCount() != 4 + m_nComps * 2) 75 if (!pDecode || pDecode->GetCount() != 4 + m_nComps * 2)
37 return FALSE; 76 return false;
38 77
39 m_xmin = pDecode->GetNumberAt(0); 78 m_xmin = pDecode->GetNumberAt(0);
40 m_xmax = pDecode->GetNumberAt(1); 79 m_xmax = pDecode->GetNumberAt(1);
41 m_ymin = pDecode->GetNumberAt(2); 80 m_ymin = pDecode->GetNumberAt(2);
42 m_ymax = pDecode->GetNumberAt(3); 81 m_ymax = pDecode->GetNumberAt(3);
43 for (uint32_t i = 0; i < m_nComps; ++i) { 82 for (uint32_t i = 0; i < m_nComps; ++i) {
44 m_ColorMin[i] = pDecode->GetNumberAt(i * 2 + 4); 83 m_ColorMin[i] = pDecode->GetNumberAt(i * 2 + 4);
45 m_ColorMax[i] = pDecode->GetNumberAt(i * 2 + 5); 84 m_ColorMax[i] = pDecode->GetNumberAt(i * 2 + 5);
46 } 85 }
47 return TRUE; 86 return true;
48 } 87 }
49 88
50 uint32_t CPDF_MeshStream::GetFlag() { 89 uint32_t CPDF_MeshStream::GetFlag() {
51 return m_BitStream.GetBits(m_nFlagBits) & 0x03; 90 return m_BitStream.GetBits(m_nFlagBits) & 0x03;
52 } 91 }
53 92
54 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) { 93 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) {
55 if (m_nCoordBits == 32) { 94 if (m_nCoordBits == 32) {
56 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * 95 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) *
57 (m_xmax - m_xmin) / (double)m_CoordMax); 96 (m_xmax - m_xmin) / (double)m_CoordMax);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (m_BitStream.IsEOF()) 144 if (m_BitStream.IsEOF())
106 return FALSE; 145 return FALSE;
107 146
108 GetCoords(vertex[i].x, vertex[i].y); 147 GetCoords(vertex[i].x, vertex[i].y);
109 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); 148 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y);
110 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); 149 GetColor(vertex[i].r, vertex[i].g, vertex[i].b);
111 m_BitStream.ByteAlign(); 150 m_BitStream.ByteAlign();
112 } 151 }
113 return TRUE; 152 return TRUE;
114 } 153 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698