Bug #3548: Infinite loop in rb_str_conv_enc_opts
http://redmine.ruby-lang.org/issues/show/3548

Author: Brian Buchanan
Status: Open, Priority: High
ruby -v: ruby 1.9.3dev (2010-07-07 trunk 28569) [x86_64-darwin10.4.0]

To reproduce:

require 'stringio'
StringIO.new(''.force_encoding('ISO-2022-JP')) << ''

This will loop forever, blocking the interpreter and requiring a "kill -9" to terminate ruby.  The problem is that rb_str_conv_enc_opts does not expect rb_econv_convert() to return econv_destination_buffer_full when the input string length is 0.  It attempts to expand the destination buffer by doubling its allocation, which will never be successful when the initial allocation was zero.

The attached patch fixes the problem in rb_str_conv_enc_opts().  I suspect that the ISO-2022-JP encoder should also not be returning econv_destination_buffer_full when processing an empty string.


----------------------------------------
http://redmine.ruby-lang.org