Fix: Remote Denial of Service (Infinite Loop) in CharsetDecoder#588
Fix: Remote Denial of Service (Infinite Loop) in CharsetDecoder#588OxBat wants to merge 7 commits intoapache:masterfrom
Conversation
When decoding invalid byte sequences (e.g. 0xFF in UTF-8), apr_xlate returns
an error without consuming input. This caused an infinite loop where the
decoder retried the same byte forever.
This patch forces the decoder to skip the invalid byte and insert a
replacement character ('?') to ensure forward progress.
|
this seems like a pretty easy thing to add a test for to prove that it is working correctly, could you add a test to the |
Add a test for handling malformed input in APRCharsetDecoder.
|
Done! I added I purposely requested ISO-8859-2 in the test. If I used standard UTF-8, log4cxx would use its internal optimized decoder (skipping APR) and wouldn't hit the bug I fixed. |
Added a test for handling malformed input in the CharsetDecoder.
|
your test does not appear to work properly. If I revert the changes to |
Added #include <log4cxx/helpers/exception.h> to fix compilation error in unit test
|
The test is too flaky as apr_xlate_conv_buffer relies on the iconv whose behaviour varies as versions change. #625 adds robustness checks to a number of decoder implementation including APRCharsetDecoder |
Summary
I identified a Remote Denial of Service vulnerability in
CharsetDecoder(specificallyAPRCharsetDecoder).When processing untrusted network input, malformed byte sequences trigger an infinite loop.
The Loop:
When
apr_xlate_conv_bufferencounters an invalid byte (like0xFFin UTF-8), it returns an error status (APR_BADCH) but consumes 0 bytes.The previous loop logic exited on error, but without advancing the buffer pointer. If the caller (e.g.,
SocketNode) retries decoding the remaining buffer, it hits the same byte again indefinitely (100% CPU).The Fix:
I updated the
decodeloop to detect when an error occurs without consuming input. In this case, it now:APR_INCOMPLETE(valid partial packet).?) to the output.APR_SUCCESSto continue decoding the rest of the stream.