Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-369

Load Properties File Fails When There Are multibyte Characters in the Path

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.10.0
    • 0.11.0
    • Configurator
    • None
    • Windows XP SP2
      VC8.0SP1

    Description

      Load properties file fails when calling PropertyConfigurator::configure using a MBCS string which type is char * or std::string and contains multibyte characters, such as Chinese characters.

      Analyse
      When calling PropertyConfigurator::configure using a MBCS string which type is char * or std::string, the constructor of File will call Transcoder::decode to convert MBCS string to DBCS string. When meets the byte which is greater than or equal to 0x80, the function will call MbstowcsCharsetDecoder::decode to process the following characters. But there is an error in MbstowcsCharsetDecoder::decode when calculating the offset after calling mbsrtowcs.

      size_t converted = mbsrtowcs(buf, // This function returns the number of wide characters, maybe not equal to the number of the bytes of multibyte characters
      &src,
      requested,
      &mbstate);
      if (converted == (size_t) -1) {
      stat = APR_BADARG;
      in.position(src - in.data());
      break;
      } else {
      stat = append(out, buf);
      in.position(in.position() + converted); // Here, the number of the bytes of multibyte characters should be added, not the number of wide characters
      }

      The path "D:\Temp\中文文件夹\STC\Config\Log.properties" becomes "D:\Temp\中文文件夹\STC\Config\Log.propertiesrties" after convertion.
      There are 10 bytes for the 5 Chinese characters, but only 5 wide characters. Because the error above, last 5 characters repeated.

      Attachments

        Issue Links

          Activity

            People

              tschoening Thorsten Schöning
              starwalker Starwalker
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: