Index: pack.c =================================================================== --- pack.c (revision 46990) +++ pack.c (working copy) @@ -946,8 +946,8 @@ static void encodes(VALUE str, const char *s, long len, int type, int tail_lf) { - enum {buff_size = 4096, encoded_unit = 4}; - char buff[buff_size + 1]; /* +1 for tail_lf */ + enum {buff_size = 256, encoded_unit = 4}; + char buff[buff_size]; long i = 0; const char *trans = type == 'u' ? uu_table : b64_table; char padding; @@ -968,7 +968,7 @@ s += 3; len -= 3; } - if (buff_size-i < encoded_unit) { + if ( ( buff_size-i < encoded_unit ) || len < 3 ) { rb_str_buf_cat(str, buff, i); i = 0; }