From 4f70b53efb39e9b9b868d99999582282be57fe50 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 21 Apr 2016 10:54:40 -0700 Subject: Only call shading code with streams. There are 4 types of meshes that attempt to convert the shading object into a stream. According to spec (section 8.7.4.1 table 76), the shading object can be a stream or a dictionary. All of this shading code assumes it can load the mesh from a stream. The original code just early exited if it was not a stream. We skip the call if it is not a stream. BUG=pdfium:481 Review URL: https://codereview.chromium.org/1908903003 --- core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 6ac380e43a..c235fd98cb 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -889,21 +889,31 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, pColorSpace, alpha); break; case kFreeFormGouraudTriangleMeshShading: { - DrawFreeGouraudShading(pBitmap, &FinalMatrix, - ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, - pColorSpace, alpha); + // 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->m_pShadingObj)) { + DrawFreeGouraudShading(pBitmap, &FinalMatrix, pStream, pFuncs, nFuncs, + pColorSpace, alpha); + } } break; case kLatticeFormGouraudTriangleMeshShading: { - DrawLatticeGouraudShading(pBitmap, &FinalMatrix, - ToStream(pPattern->m_pShadingObj), pFuncs, - nFuncs, pColorSpace, alpha); + // 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->m_pShadingObj)) { + DrawLatticeGouraudShading(pBitmap, &FinalMatrix, pStream, pFuncs, + nFuncs, pColorSpace, alpha); + } } break; case kCoonsPatchMeshShading: case kTensorProductPatchMeshShading: { - DrawCoonPatchMeshes( - pPattern->m_ShadingType == kTensorProductPatchMeshShading, pBitmap, - &FinalMatrix, ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, - pColorSpace, fill_mode, alpha); + // 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->m_pShadingObj)) { + DrawCoonPatchMeshes( + pPattern->m_ShadingType == kTensorProductPatchMeshShading, pBitmap, + &FinalMatrix, pStream, pFuncs, nFuncs, pColorSpace, fill_mode, + alpha); + } } break; } if (bAlphaMode) { -- cgit v1.2.3