Apply pdfium_noshorten_config to xfa/fde

Patch over some dubious indexing with checked_cast<>.

Change-Id: I36af2ffd7da900fd108c8dc73b8e7ea8daedd3de
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/90712
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fde/BUILD.gn b/xfa/fde/BUILD.gn
index 1c6b6b4..2c754d1 100644
--- a/xfa/fde/BUILD.gn
+++ b/xfa/fde/BUILD.gn
@@ -17,16 +17,17 @@
     "cfde_wordbreak_data.cpp",
     "cfde_wordbreak_data.h",
   ]
+  configs += [
+    "../../:pdfium_strict_config",
+    "../../:pdfium_noshorten_config",
+    "../:xfa_warnings",
+  ]
   deps = [
     "../../core/fxcrt",
     "../../core/fxge",
     "../fgas/font",
     "../fgas/layout",
   ]
-  configs += [
-    "../../:pdfium_strict_config",
-    "../:xfa_warnings",
-  ]
   visibility = [ "../../*" ]
 }
 
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index ce950a3..05823e8 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -13,6 +13,7 @@
 #include "core/fxge/text_char_pos.h"
 #include "third_party/base/check.h"
 #include "third_party/base/notreached.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "xfa/fde/cfde_textout.h"
 #include "xfa/fde/cfde_wordbreak_data.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
@@ -947,7 +948,7 @@
       // move the cursor after it.
       bool closer_to_left =
           (point.x - rects[i].left < rects[i].right() - point.x);
-      int caret_pos = (closer_to_left ? i : i + 1);
+      size_t caret_pos = closer_to_left ? i : i + 1;
       size_t pos = start_it->nStart + caret_pos;
       if (pos >= text_length_)
         return text_length_;
@@ -1069,7 +1070,8 @@
       txtEdtPiece.rtPiece.top = current_line_start;
       txtEdtPiece.rtPiece.width = piece->m_iWidth / 20000.0f;
       txtEdtPiece.rtPiece.height = line_spacing_;
-      txtEdtPiece.nStart = current_piece_start;
+      txtEdtPiece.nStart =
+          pdfium::base::checked_cast<int32_t>(current_piece_start);
       txtEdtPiece.nCount = piece->GetLength();
       txtEdtPiece.nBidiLevel = piece->m_iBidiLevel;
       txtEdtPiece.dwCharStyles = piece->m_dwCharStyles;
@@ -1204,10 +1206,8 @@
 }
 
 void CFDE_TextEditEngine::Iterator::SetAt(size_t nIndex) {
-  if (static_cast<size_t>(nIndex) >= engine_->GetLength())
-    current_position_ = engine_->GetLength();
-  else
-    current_position_ = nIndex;
+  nIndex = std::min(nIndex, engine_->GetLength());
+  current_position_ = pdfium::base::checked_cast<int32_t>(nIndex);
 }
 
 bool CFDE_TextEditEngine::Iterator::IsEOF(bool bPrev) const {
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 0ddad29..777e031 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -22,6 +22,7 @@
 #include "core/fxge/fx_font.h"
 #include "core/fxge/text_char_pos.h"
 #include "third_party/base/check.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
 #include "xfa/fgas/layout/cfgas_txtbreak.h"
 
@@ -372,7 +373,7 @@
   for (int32_t i = 0; i < iCount; i++) {
     const CFGAS_BreakPiece* pPiece = m_pTxtBreak->GetBreakPieceUnstable(i);
     int32_t iPieceChars = pPiece->GetLength();
-    int32_t iChar = *pStartChar;
+    size_t iChar = *pStartChar;
     int32_t iWidth = 0;
     int32_t j = 0;
     for (; j < iPieceChars; j++) {
@@ -507,7 +508,7 @@
   CFGAS_TxtBreak::Run tr;
   tr.wsStr = m_wsText.Substr(pPiece->start_char);
   tr.pWidths = &m_CharWidths[pPiece->start_char];
-  tr.iLength = pPiece->char_count;
+  tr.iLength = pdfium::base::checked_cast<int32_t>(pPiece->char_count);
   tr.pFont = m_pFont;
   tr.fFontSize = m_fFontSize;
   tr.dwStyles = m_dwTxtBkStyles;