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

Unified Diff: core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp

Issue 2020183004: Validate the BitsPerFlag entry in shading dictionaries. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bug_616246
Patch Set: Add check Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/fpdf_page/fpdf_page_parser.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
index 754394da70a2e5c3272127bd7af44d23bd5e2ffd..7896f83459ab7c80669ffdf27ac0931040eaeb0a 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
@@ -411,8 +411,9 @@ void DrawFreeGouraudShading(
int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
- CPDF_MeshStream stream(funcs, pCS);
- if (!stream.Load(pShadingStream))
+ CPDF_MeshStream stream(kFreeFormGouraudTriangleMeshShading, funcs,
+ pShadingStream, pCS);
+ if (!stream.Load())
return;
CPDF_MeshVertex triangle[3];
@@ -450,8 +451,9 @@ void DrawLatticeGouraudShading(
if (row_verts < 2)
return;
- CPDF_MeshStream stream(funcs, pCS);
- if (!stream.Load(pShadingStream))
+ CPDF_MeshStream stream(kLatticeFormGouraudTriangleMeshShading, funcs,
+ pShadingStream, pCS);
+ if (!stream.Load())
return;
std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex(
@@ -724,24 +726,8 @@ struct CPDF_PatchDrawer {
}
};
-bool CheckCoonTensorPara(const CPDF_MeshStream& stream) {
- uint32_t coord = stream.CoordBits();
- bool bCoordBitsValid =
- (coord == 1 || coord == 2 || coord == 4 || coord == 8 || coord == 12 ||
- coord == 16 || coord == 24 || coord == 32);
-
- uint32_t comp = stream.CompBits();
- bool bCompBitsValid = (comp == 1 || comp == 2 || comp == 4 || comp == 8 ||
- comp == 12 || comp == 16);
-
- uint32_t flag = stream.FlagBits();
- bool bFlagBitsValid = (flag == 2 || flag == 4 || flag == 8);
-
- return bCoordBitsValid && bCompBitsValid && bFlagBitsValid;
-}
-
void DrawCoonPatchMeshes(
- FX_BOOL bTensor,
+ ShadingType type,
CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
@@ -750,13 +736,13 @@ void DrawCoonPatchMeshes(
int fill_mode,
int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
+ ASSERT(type == kCoonsPatchMeshShading ||
+ type == kTensorProductPatchMeshShading);
CFX_FxgeDevice device;
device.Attach(pBitmap, false, nullptr, false);
- CPDF_MeshStream stream(funcs, pCS);
- if (!stream.Load(pShadingStream))
- return;
- if (!CheckCoonTensorPara(stream))
+ CPDF_MeshStream stream(type, funcs, pShadingStream, pCS);
+ if (!stream.Load())
return;
CPDF_PatchDrawer patch;
@@ -766,11 +752,10 @@ void DrawCoonPatchMeshes(
patch.path.SetPointCount(13);
FX_PATHPOINT* pPoints = patch.path.GetPoints();
pPoints[0].m_Flag = FXPT_MOVETO;
- for (int i = 1; i < 13; i++) {
+ for (int i = 1; i < 13; i++)
pPoints[i].m_Flag = FXPT_BEZIERTO;
- }
CFX_PointF coords[16];
- int point_count = bTensor ? 16 : 12;
+ int point_count = type == kTensorProductPatchMeshShading ? 16 : 12;
while (!stream.BitStream()->IsEOF()) {
uint32_t flag = stream.GetFlag();
int iStartPoint = 0, iStartColor = 0, i = 0;
@@ -934,10 +919,8 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
// The shading object can be a stream or a dictionary. We do not handle
// the case of dictionary at the moment.
if (CPDF_Stream* pStream = ToStream(pPattern->GetShadingObject())) {
- DrawCoonPatchMeshes(
- pPattern->GetShadingType() == kTensorProductPatchMeshShading,
- pBitmap, &FinalMatrix, pStream, funcs, pColorSpace, fill_mode,
- alpha);
+ DrawCoonPatchMeshes(pPattern->GetShadingType(), pBitmap, &FinalMatrix,
+ pStream, funcs, pColorSpace, fill_mode, alpha);
}
} break;
}
« no previous file with comments | « core/fpdfapi/fpdf_page/fpdf_page_parser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698