From 1721392dfac7e80604093be5f6d73fdabeb67783 Mon Sep 17 00:00:00 2001
From: Alberto Massari <amassari@apache.org>
Date: Tue, 27 Dec 2011 10:08:43 +0000
Subject: [PATCH] Don't report a transcoding error if the invalid character is
 not at the start of the buffer, it could be an incomplete buffer
 (XERCESC-1936)

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@1224886 13f79535-47bb-0310-9956-ffa450edef68
---
 src/xercesc/util/Transcoders/ICU/ICUTransService.cpp          | 4 ++--
 .../util/Transcoders/IconvGNU/IconvGNUTransService.cpp        | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/xercesc/util/Transcoders/ICU/ICUTransService.cpp b/src/xercesc/util/Transcoders/ICU/ICUTransService.cpp
index 38afb4cc1..b10bdb782 100644
--- a/src/xercesc/util/Transcoders/ICU/ICUTransService.cpp
+++ b/src/xercesc/util/Transcoders/ICU/ICUTransService.cpp
@@ -666,7 +666,7 @@ ICUTranscoder::transcodeTo( const   XMLCh* const    srcData
     );
 
     // Rememember the status before we possibly overite the error code
-    const bool res = (err == U_ZERO_ERROR);
+    const bool res = ((err == U_ZERO_ERROR) || (err == U_BUFFER_OVERFLOW_ERROR && startSrc > srcPtr));
 
     // Put the old handler back
     err = U_ZERO_ERROR;
@@ -738,7 +738,7 @@ bool ICUTranscoder::canTranscodeTo(const unsigned int toCheck)
          , &err
          );
 
-    // Set upa temp buffer to format into. Make it more than big enough
+    // Set up a temp buffer to format into. Make it more than big enough
     char            tmpBuf[64];
     char*           startTarget = tmpBuf;
     const UChar*    startSrc = srcBuf;
diff --git a/src/xercesc/util/Transcoders/IconvGNU/IconvGNUTransService.cpp b/src/xercesc/util/Transcoders/IconvGNU/IconvGNUTransService.cpp
index 766e25bff..51d1f279c 100644
--- a/src/xercesc/util/Transcoders/IconvGNU/IconvGNUTransService.cpp
+++ b/src/xercesc/util/Transcoders/IconvGNU/IconvGNUTransService.cpp
@@ -1041,7 +1041,7 @@ XMLSize_t    IconvGNUTranscoder::transcodeFrom
     char    *orgTarget = startTarget;
     size_t    srcLen = srcCount;
     size_t    prevSrcLen = srcLen;
-    unsigned int toReturn = 0;
+    XMLSize_t toReturn = 0;
     bytesEaten = 0;
 
     XMLMutexLock lockConverter(&fMutex);
@@ -1049,6 +1049,8 @@ XMLSize_t    IconvGNUTranscoder::transcodeFrom
     for (size_t cnt = 0; cnt < maxChars && srcLen; cnt++) {
         size_t    rc = iconvFrom(startSrc, &srcLen, &orgTarget, uChSize());
         if (rc == (size_t)-1) {
+            if (errno == EINVAL && cnt > 0)
+                break;
             if (errno != E2BIG || prevSrcLen == srcLen) {
                 ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadSrcSeq, getMemoryManager());
             }
-- 
GitLab