Avoid result string with trailing NUL in XFA Decode().

Fix one case where breaking early in a loop produced a two-char
string where the second char was inadvertently NUL.

-- Add test for one more possibility in this same loop.

Change-Id: I4fb8c87b9a0bcbb9ec2a9b3845cced3d8f08494e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116990
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 5830139..1a66c90 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -566,12 +566,12 @@
       wsResultBuf.AppendChar(ch);
       continue;
     }
-
     wchar_t chTemp = 0;
     int32_t iCount = 0;
     while (iCount < 2) {
-      if (++i >= iLen)
-        break;
+      if (++i >= iLen) {
+        return WideString();
+      }
       chTemp *= 16;
       ch = pData[i];
       if (!FXSYS_IsWideHexDigit(ch))
diff --git a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
index 89f651f..724251c 100644
--- a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
@@ -694,8 +694,9 @@
   ExecuteExpectString(R"(Decode("~%26^&*()_+|`{", "mbogo"))", "~&^&*()_+|`{");
   ExecuteExpectString(R"(Decode("~%26^&*()_+|`{"))", "~&^&*()_+|`{");
   ExecuteExpectString(R"(Decode("~%~~"))", "");
+  ExecuteExpectString(R"(Decode("?%f~"))", "");
   ExecuteExpectString(R"(Decode("?%~"))", "");
-  ExecuteExpectString(R"(Decode("?%"))", "?");
+  ExecuteExpectString(R"(Decode("?%"))", "");
 }
 
 TEST_F(CFXJSE_FormCalcContextEmbedderTest, Encode) {