From: Yukihiro Matsumoto Date: 2004-10-20T21:56:53+09:00 Subject: [ruby-dev:24542] Re: IO#readpartial dumps core まつもと ゆきひろです In message "Re: [ruby-dev:24540] IO#readpartial dumps core" on Wed, 20 Oct 2004 20:19:00 +0900, Tanaka Akira writes: | |次のようにすると core を吐きます。 | |% ./ruby -d -e ' |r, w = IO.pipe |len = 0x20000 |buf = "\0" * len |Thread.new { | Thread.pass | buf.replace "" | (len/4096).times { w << "a"*4096 } } |r.readpartial(len, buf) |' |-e:9: [BUG] Segmentation fault |ruby 1.9.0 (2004-10-20) [i686-linux] | |-e:9: [BUG] Segmentation fault |ruby 1.9.0 (2004-10-20) [i686-linux] | |Index: io.c おお、今回はパッチが付いている。 でも、EOFに突き当たるよりもバッファが書き換わったことを検出 した方が良いんじゃないですかね。 --- io.c 20 Oct 2004 03:42:53 -0000 1.306 +++ io.c 20 Oct 2004 12:56:42 -0000 @@ -1133,2 +1133,5 @@ io_readpartial(argc, argv, io) READ_CHECK(fptr->f); + if (RSTRING(str)->len != len) { + rb_raise(rb_eRuntimeError, "buffer string modified"); + } n = read_buffered_data(RSTRING(str)->ptr, len, fptr->f);