From ac8357b3ec7e1fe4000ebcae5ce65a38bfeb5cb1 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Mon, 28 May 2018 20:06:19 +0000 Subject: Revert 'Remove almost all usages of CFX_FixedBufGrow with std::vector' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a manual revert of the CL at: https://pdfium-review.googlesource.com/c/pdfium/+/32159 The only file manually changed was cpdf_renderstatus.cpp Reason for revert: the bug below shows that sometimes the vector size used is larger than the parameter given to CFX_FixedBufGrow. Thus, we will revert, then add vectors using std::max unless it's clear from the code that the code will never access indices outside. Bug: chromium:847247 Change-Id: Iee54af023c8564824418a7d34a6385b0bc418ff0 Reviewed-on: https://pdfium-review.googlesource.com/33050 Reviewed-by: dsinclair Commit-Queue: Nicolás Peña Moreno --- core/fpdfapi/render/cpdf_renderstatus.cpp | 36 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'core/fpdfapi/render/cpdf_renderstatus.cpp') diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 8c3c8796e4..f99000bb69 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -49,6 +49,7 @@ #include "core/fpdfapi/render/cpdf_type3cache.h" #include "core/fpdfdoc/cpdf_occontext.h" #include "core/fxcrt/autorestorer.h" +#include "core/fxcrt/cfx_fixedbufgrow.h" #include "core/fxcrt/fx_safe_types.h" #include "core/fxcrt/maybe_owned.h" #include "core/fxge/cfx_defaultrenderdevice.h" @@ -151,7 +152,9 @@ void DrawAxialShading(const RetainPtr& pBitmap, float y_span = end_y - start_y; float axis_len_square = (x_span * x_span) + (y_span * y_span); - std::vector results(total_results); + CFX_FixedBufGrow result_array(total_results); + float* pResults = result_array; + memset(pResults, 0, total_results * sizeof(float)); uint32_t rgb_array[kShadingSteps]; for (int i = 0; i < kShadingSteps; i++) { float input = (t_max - t_min) * i / kShadingSteps + t_min; @@ -159,14 +162,14 @@ void DrawAxialShading(const RetainPtr& pBitmap, for (const auto& func : funcs) { if (func) { int nresults = 0; - if (func->Call(&input, 1, results.data() + offset, &nresults)) + if (func->Call(&input, 1, pResults + offset, &nresults)) offset += nresults; } } float R = 0.0f; float G = 0.0f; float B = 0.0f; - pCS->GetRGB(results.data(), &R, &G, &B); + pCS->GetRGB(pResults, &R, &G, &B); rgb_array[i] = FXARGB_TODIB(FXARGB_MAKE(alpha, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); @@ -235,7 +238,9 @@ void DrawRadialShading(const RetainPtr& pBitmap, bEndExtend = !!pArray->GetIntegerAt(1); } - std::vector results(total_results); + CFX_FixedBufGrow result_array(total_results); + float* pResults = result_array; + memset(pResults, 0, total_results * sizeof(float)); uint32_t rgb_array[kShadingSteps]; for (int i = 0; i < kShadingSteps; i++) { float input = (t_max - t_min) * i / kShadingSteps + t_min; @@ -243,14 +248,14 @@ void DrawRadialShading(const RetainPtr& pBitmap, for (const auto& func : funcs) { if (func) { int nresults; - if (func->Call(&input, 1, results.data() + offset, &nresults)) + if (func->Call(&input, 1, pResults + offset, &nresults)) offset += nresults; } } float R = 0.0f; float G = 0.0f; float B = 0.0f; - pCS->GetRGB(results.data(), &R, &G, &B); + pCS->GetRGB(pResults, &R, &G, &B); rgb_array[i] = FXARGB_TODIB(FXARGB_MAKE(alpha, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); @@ -362,7 +367,9 @@ void DrawFuncShading(const RetainPtr& pBitmap, int height = pBitmap->GetHeight(); int pitch = pBitmap->GetPitch(); - std::vector results(total_results); + CFX_FixedBufGrow result_array(total_results); + float* pResults = result_array; + memset(pResults, 0, total_results * sizeof(float)); for (int row = 0; row < height; row++) { uint32_t* dib_buf = (uint32_t*)(pBitmap->GetBuffer() + row * pitch); for (int column = 0; column < width; column++) { @@ -376,7 +383,7 @@ void DrawFuncShading(const RetainPtr& pBitmap, for (const auto& func : funcs) { if (func) { int nresults; - if (func->Call(input, 2, results.data() + offset, &nresults)) + if (func->Call(input, 2, pResults + offset, &nresults)) offset += nresults; } } @@ -384,7 +391,7 @@ void DrawFuncShading(const RetainPtr& pBitmap, float R = 0.0f; float G = 0.0f; float B = 0.0f; - pCS->GetRGB(results.data(), &R, &G, &B); + pCS->GetRGB(pResults, &R, &G, &B); dib_buf[column] = FXARGB_TODIB(FXARGB_MAKE( alpha, (int32_t)(R * 255), (int32_t)(G * 255), (int32_t)(B * 255))); } @@ -2049,14 +2056,13 @@ void CPDF_RenderStatus::DrawShading(const CPDF_ShadingPattern* pPattern, const CPDF_Array* pBackColor = pDict->GetArrayFor("Background"); if (pBackColor && pBackColor->GetCount() >= pColorSpace->CountComponents()) { - std::vector comps; - comps.reserve(pColorSpace->CountComponents()); + CFX_FixedBufGrow comps(pColorSpace->CountComponents()); for (uint32_t i = 0; i < pColorSpace->CountComponents(); i++) - comps.push_back(pBackColor->GetNumberAt(i)); + comps[i] = pBackColor->GetNumberAt(i); float R = 0.0f; float G = 0.0f; float B = 0.0f; - pColorSpace->GetRGB(comps.data(), &R, &G, &B); + pColorSpace->GetRGB(comps, &R, &G, &B); background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), (int32_t)(B * 255)); } @@ -2596,11 +2602,11 @@ RetainPtr CPDF_RenderStatus::LoadSMask( int src_pitch = bitmap.GetPitch(); std::vector transfers(256); if (pFunc) { - std::vector results(pFunc->CountOutputs()); + CFX_FixedBufGrow results(pFunc->CountOutputs()); for (int i = 0; i < 256; i++) { float input = (float)i / 255.0f; int nresult; - pFunc->Call(&input, 1, results.data(), &nresult); + pFunc->Call(&input, 1, results, &nresult); transfers[i] = FXSYS_round(results[0] * 255); } } else { -- cgit v1.2.3