次のスクリプトが core を吐きます。

Z(2):akr@flux% cat tst
#!/usr/local/bin/ruby

require 'zlib';

f = open('z', 'w')
p f.id

s = "a"
begin
  s = s.dup
end while s.id < f.id

g = GzipWriter.new(f)
p g.id

print "script ends.\n"
Z(2):akr@flux% ./ruby tst
67624928
67627948
script ends.
tst:16:in `write': stack level too deep (SystemStackError)
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
         ... 137613 levels...
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16:in `write'
        from tst:16
tst:16: [BUG] Segmentation fault
ruby 1.7.0 (2000-12-29) [i386-freebsdelf4.0]
zsh: abort (core dumped)  ./ruby tst

ruby は [BUG] だと述べていますが、これは Ruby と Ruby/zlib のどちらの
BUG なのでしょう?

Z(2):akr@flux% gdb ruby ruby.core 
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd"...
Core was generated by `ruby'.
Program terminated with signal 6, Abort trap.
Reading symbols from /usr/lib/libcrypt.so.2...done.
Reading symbols from /usr/lib/libxpg4.so.2...done.
Reading symbols from /usr/lib/libm.so.2...done.
Reading symbols from /usr/lib/libc.so.4...done.
Reading symbols from /home/akr/src/ruby/lib/ruby/1.7/i386-freebsdelf4.0/zlib.so...done.
Reading symbols from /usr/lib/libz.so.2...done.
Reading symbols from /usr/libexec/ld-elf.so.1...done.
#0  0x2814f030 in kill () from /usr/lib/libc.so.4
(gdb) where
#0  0x2814f030 in kill () from /usr/lib/libc.so.4
#1  0x28187f7e in abort () from /usr/lib/libc.so.4
#2  0x80af586 in rb_bug (fmt=0x80c512e "Segmentation fault") at error.c:178
#3  0x80982c7 in sigsegv (sig=11) at signal.c:385
#4  0xbfbfffac in ?? ()
#5  0x8056a13 in rb_exc_raise (mesg=135255496) at eval.c:3360
#6  0x80afe89 in rb_raise (exc=135259636, fmt=0x80b1880 "stack level too deep") at error.c:598
#7  0x80585ab in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcff1c0, body=0x8101e98, nosuper=1)
    at eval.c:4209
#8  0x8058f36 in rb_call (klass=135275296, recv=135249856, mid=6337, argc=1, argv=0xbbcff1c0, scope=1) at eval.c:4453
#9  0x8059159 in rb_funcall (recv=135249856, mid=6337, n=1) at eval.c:4527
#10 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
#11 0x805830c in call_cfunc (func=0x806855c <io_write>, recv=135249856, len=1, argc=1, argv=0xbbcff3a0) at eval.c:4116
#12 0x80587fd in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcff3a0, body=0x8101e98, nosuper=1)
    at eval.c:4249
#13 0x8058f36 in rb_call (klass=135275296, recv=135249856, mid=6337, argc=1, argv=0xbbcff3a0, scope=1) at eval.c:4453
#14 0x8059159 in rb_funcall (recv=135249856, mid=6337, n=1) at eval.c:4527
#15 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
#16 0x805830c in call_cfunc (func=0x806855c <io_write>, recv=135249856, len=1, argc=1, argv=0xbbcff580) at eval.c:4116
#17 0x80587fd in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcff580, body=0x8101e98, nosuper=1)
    at eval.c:4249
#18 0x8058f36 in rb_call (klass=135275296, recv=135249856, mid=6337, argc=1, argv=0xbbcff580, scope=1) at eval.c:4453
#19 0x8059159 in rb_funcall (recv=135249856, mid=6337, n=1) at eval.c:4527
#20 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
#21 0x805830c in call_cfunc (func=0x806855c <io_write>, recv=135249856, len=1, argc=1, argv=0xbbcff760) at eval.c:4116
#22 0x80587fd in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcff760, body=0x8101e98, nosuper=1)
    at eval.c:4249
#23 0x8058f36 in rb_call (klass=135275296, recv=135249856, mid=6337, argc=1, argv=0xbbcff760, scope=1) at eval.c:4453
#24 0x8059159 in rb_funcall (recv=135249856, mid=6337, n=1) at eval.c:4527
#25 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
#26 0x805830c in call_cfunc (func=0x806855c <io_write>, recv=135249856, len=1, argc=1, argv=0xbbcff940) at eval.c:4116
#27 0x80587fd in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcff940, body=0x8101e98, nosuper=1)
    at eval.c:4249
#28 0x8058f36 in rb_call (klass=135275296, recv=135249856, mid=6337, argc=1, argv=0xbbcff940, scope=1) at eval.c:4453
#29 0x8059159 in rb_funcall (recv=135249856, mid=6337, n=1) at eval.c:4527
#30 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
#31 0x805830c in call_cfunc (func=0x806855c <io_write>, recv=135249856, len=1, argc=1, argv=0xbbcffb20) at eval.c:4116
#32 0x80587fd in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcffb20, body=0x8101e98, nosuper=1)
    at eval.c:4249
#33 0x8058f36 in rb_call (klass=135275296, recv=135249856, mid=6337, argc=1, argv=0xbbcffb20, scope=1) at eval.c:4453
#34 0x8059159 in rb_funcall (recv=135249856, mid=6337, n=1) at eval.c:4527
#35 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
#36 0x805830c in call_cfunc (func=0x806855c <io_write>, recv=135249856, len=1, argc=1, argv=0xbbcffd00) at eval.c:4116
#37 0x80587fd in rb_call0 (klass=135275296, recv=135249856, id=6337, argc=1, argv=0xbbcffd00, body=0x8101e98, nosuper=1)
---Type <return> to continue, or q <return> to quit---q
 at Quit
(gdb) up 100000
#100000 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
236             return rb_funcall(io, id_write, 1, str);
(gdb) up 100000
#200000 0x8068651 in io_write (io=135249856, str=135255736) at io.c:236
236             return rb_funcall(io, id_write, 1, str);
(gdb) up 1000000
#688143 0x8050161 in _start ()
(gdb) down
#688142 0x80501ea in main (argc=2, argv=0xbfbff33c, envp=0xbfbff348) at main.c:50
50          ruby_run();
(gdb) down
#688141 0x8051808 in ruby_run () at eval.c:1172
1172        ruby_stop(ex);
(gdb) down
#688140 0x805171a in ruby_stop (ex=0) at eval.c:1149
1149        ruby_finalize();
(gdb) down
#688139 0x8051669 in ruby_finalize () at eval.c:1127
1127        rb_gc_call_finalizer_at_exit();
(gdb) down
#688138 0x8065894 in rb_gc_call_finalizer_at_exit () at gc.c:1248
1248                    (*RANY(p)->as.data.dfree)(DATA_PTR(p));
(gdb) down
#688137 0x281a7f39 in gzip_free (gz=0x8124100) at zlib.c:1076
1076                    gz->close(gz);
(gdb) down
#688136 0x281a8c14 in gzipwriter_close (gz=0x8124100) at zlib.c:1531
1531            gzip_write_io(gz, zstream_detach_buffer(&gz->z));
(gdb) down
#688135 0x281a84c9 in gzip_write_io (gz=0x8124100, str=135255736) at zlib.c:1282
1282            rb_funcall(gz->io, id_write, 1, str);
(gdb) 
Z(2):akr@flux% 

# ちなみに、これと直接には関係ありませんが 
#   ruby -e 'require "zlib"; f = GzipWriter.new(1); f.print "a\n"' 
# が core を吐くのは Ruby/zlib の問題だと思う。
-- 
[田中 哲][たなか あきら][Tanaka Akira]
「ああ、それは大丈夫だよぉ。カイロを持って行くもぉん$(C⊇」
  (気象精霊記2 爆弾気分の低気圧, 清水文化)