GNOME Bugzilla – Bug 58472
g_io_channeal_read_line* error in "UTF-8" encoding
Last modified: 2004-12-22 21:47:04 UTC
g_io_channel_read_line and g_io_channel_read_line_string causes error: GLib-CRITICAL **: file gstring.c: line 623 (g_string_erase): assertion `pos + len <= string->len' failed with default encoding "UTF-8" . To reproduce, comment out a line below of io-channel.c. g_io_channel_set_encoding (gio_r, encoding, &gerr);
A patch to giochannel.c will be attached for code review. channel->encoded_read_buf should always be used regardless of do_encode flag, as channel->read_buf was already copied to it and deleted in g_io_channel_fill_buffer (line 1199).
Created attachment 839 [details] [review] always use encoded_read_buf
This isn't quite correct. encoded_read_buf isn't used at all if the encoding is NULL. The test needs to be changed from channel->do_encode to channel->encoding instead.
When I set "UTF-8" to io channel or don't set encoding at all, g_io_channel_read_line_string or g_io_channel_read_line causes error. I think the patch may not do a right thing, but actually makes the above case work. I don't think the case of channel->encoding == NULL should occur in the current code. g_io_channel_init initializes this to "UTF-8" and setting NULL encoding with g_io_channel_set_encoding should not work.
Setting an encoding of NULL makes GIOChannel binary safe. Changing the test from "if (channel->do_encode)" to "if (channel->encoding)" makes use_buf equal to encoded_read_buf for UTF-8, and equal to read_buf for NULL. I've committed a fix which works for both NULL and UTF-8 to CVS.
I verified the fix in revision 1.1.8 of giochannel.[ch]. marked the bug fixed.http://bugzilla.gnome.org/bug_status.html