From e797c6f8e64667be460742a78bff8e7818217172 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 9 Oct 2018 18:12:34 +0000 Subject: Fix a C-style cast in FPDFPage_TransFormWithClip(). There is no guarantee that CFX_Matrix and FS_MATRIX are the same. Also change the code to do some early returns. Change-Id: I6b5b42cafe370cd43ec1dd5885bba8e37c4a1341 Reviewed-on: https://pdfium-review.googlesource.com/c/43611 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- fpdfsdk/fpdf_transformpage.cpp | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 52b9fd41df..87f39ed072 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -158,28 +158,30 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, // Need to transform the patterns as well. CPDF_Dictionary* pRes = pPageDict->GetDictFor(pdfium::page_object::kResources); - if (pRes) { - CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); - if (pPattenDict) { - for (const auto& it : *pPattenDict) { - CPDF_Object* pObj = it.second.get(); - if (pObj->IsReference()) - pObj = pObj->GetDirect(); - - CPDF_Dictionary* pDict = nullptr; - if (pObj->IsDictionary()) - pDict = pObj->AsDictionary(); - else if (CPDF_Stream* pObjStream = pObj->AsStream()) - pDict = pObjStream->GetDict(); - else - continue; - - CFX_Matrix m = pDict->GetMatrixFor("Matrix"); - CFX_Matrix t = *(CFX_Matrix*)matrix; - m.Concat(t); - pDict->SetMatrixFor("Matrix", m); - } - } + if (!pRes) + return true; + + CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern"); + if (!pPattenDict) + return true; + + for (const auto& it : *pPattenDict) { + CPDF_Object* pObj = it.second.get(); + if (pObj->IsReference()) + pObj = pObj->GetDirect(); + + CPDF_Dictionary* pDict = nullptr; + if (pObj->IsDictionary()) + pDict = pObj->AsDictionary(); + else if (CPDF_Stream* pObjStream = pObj->AsStream()) + pDict = pObjStream->GetDict(); + else + continue; + + CFX_Matrix m = pDict->GetMatrixFor("Matrix"); + m.Concat(CFX_Matrix(matrix->a, matrix->b, matrix->c, matrix->d, matrix->e, + matrix->f)); + pDict->SetMatrixFor("Matrix", m); } return true; -- cgit v1.2.3