Fix unsafe-buffer usage in CXFA_ContentLayoutProcessor Convert to std::array<> as necessary. Change-Id: I89cf636646e20de2dffb72c773b1fec800e9276c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/119832 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Thomas Sepez <tsepez@google.com> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp index b568b96..e09a417 100644 --- a/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp +++ b/xfa/fxfa/layout/cxfa_contentlayoutprocessor.cpp
@@ -4,14 +4,10 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#if defined(UNSAFE_BUFFERS_BUILD) -// TODO(crbug.com/pdfium/2154): resolve buffer safety issues. -#pragma allow_unsafe_buffers -#endif - #include "xfa/fxfa/layout/cxfa_contentlayoutprocessor.h" #include <algorithm> +#include <array> #include <utility> #include <vector> @@ -42,6 +38,14 @@ namespace { +using NextPosRow = std::array<uint8_t, 9>; +constexpr std::array<const NextPosRow, 4> kNextPosTable = {{ + {{0, 1, 2, 3, 4, 5, 6, 7, 8}}, + {{6, 3, 0, 7, 4, 1, 8, 5, 2}}, + {{8, 7, 6, 5, 4, 3, 2, 1, 0}}, + {{2, 5, 8, 1, 4, 7, 0, 3, 6}}, +}}; + std::vector<WideString> SeparateStringOnSpace( pdfium::span<const wchar_t> spStr) { std::vector<WideString> ret; @@ -593,18 +597,13 @@ default: break; } - static const uint8_t nNextPos[4][9] = {{0, 1, 2, 3, 4, 5, 6, 7, 8}, - {6, 3, 0, 7, 4, 1, 8, 5, 2}, - {8, 7, 6, 5, 4, 3, 2, 1, 0}, - {2, 5, 8, 1, 4, 7, 0, 3, 6}}; - CFX_PointF pos( pNode->JSObject()->GetMeasureInUnit(XFA_Attribute::X, XFA_Unit::Pt), pNode->JSObject()->GetMeasureInUnit(XFA_Attribute::Y, XFA_Unit::Pt)); int32_t nRotate = XFA_MapRotation(pNode->JSObject()->GetInteger(XFA_Attribute::Rotate)) / 90; - int32_t nAbsoluteAnchorType = nNextPos[nRotate][nAnchorType]; + int32_t nAbsoluteAnchorType = kNextPosTable[nRotate][nAnchorType]; switch (nAbsoluteAnchorType / 3) { case 1: pos.y -= size.height / 2; @@ -1923,8 +1922,8 @@ float fContentCurRowHeight, float fContentWidthLimit, bool bRootForceTb) { - int32_t nGroupLengths[3] = {0, 0, 0}; - float fGroupWidths[3] = {0, 0, 0}; + std::array<int32_t, 3> nGroupLengths = {}; + std::array<float, 3> fGroupWidths = {}; int32_t nTotalLength = 0; for (int32_t i = 0; i < 3; i++) { nGroupLengths[i] = fxcrt::CollectionSize<int32_t>(rgCurLineLayoutItems[i]);