[ 
https://issues.apache.org/jira/browse/LOGCXX-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17173452#comment-17173452
 ] 

Robert Middleton commented on LOGCXX-398:
-----------------------------------------

Possibly I was looking at the wrong function; there's many that are very 
similar in the transcoder class so it's hard to keep them straight.

 

On the exceptions vs. LOSSCHAR, it seems like the best solution would be to 
append the LOSSCHAR, as throwing an exception from the library could cause 
unexpected issues(for example, terminate being called due to an unhandled 
exception).  If we're handling the exception inside log4cxx that's probably not 
an issue.

> Infinite loop in Transcoder::encode(const LogString& src, std::wstring& dst)
> ----------------------------------------------------------------------------
>
>                 Key: LOGCXX-398
>                 URL: https://issues.apache.org/jira/browse/LOGCXX-398
>             Project: Log4cxx
>          Issue Type: Bug
>          Components: Appender
>    Affects Versions: 0.10.0
>            Reporter: Brian Hayes
>            Assignee: Curt Arnold
>            Priority: Critical
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When building log4cxx as multi byte instead of wchar_t there's a bug in 
> Transcoder::encode(const LogString& src, std::wstring& dst).
>  
> {code:java}
> void Transcoder::encode(const LogString& src, std::wstring& dst) {
>  #if LOG4CXX_LOGCHAR_IS_WCHAR_T
>  dst.append(src);
>  #else
>  for(LogString::const_iterator i = src.begin();
>  i != src.end()
> { unsigned int cp = Transcoder::decode(src, i); encode(cp, dst); }
> #endif
>  }
> {code}
>  
> If you pass an invalid multibyte string for src the Transcoder::decode 
> function will return 0xffff and not advance the iterator i. The encode will 
> then stick cp into dst over and over. Depending on whether your 32bit or 
> 64bit you either get a crash when you blow past your 2/4 GB address space, or 
> in 64bit you use up all available system resources and essentially lock up 
> the OS.
> Here's the fix I've applied to my local version. It now does the same thing 
> that Transcoder::decode() above it does, insert a LOSSCHAR and advance the 
> iterator.
>  
> {code:java}
> void Transcoder::encode(const LogString& src, std::wstring& dst) {
>  #if LOG4CXX_LOGCHAR_IS_WCHAR_T
>  dst.append(src);
>  #else
>  for(LogString::const_iterator i = src.begin();
>  i != src.end() {
>  unsigned int cp = Transcoder::decode(src, i);
>  if (cp != 0xFFFF)
> { encode(cp, dst); }
> else
> { dst.append(1, LOSSCHAR); i++; }
> }
>  #endif
>  }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to