From: Chris Heath Date: Mon, 6 Sep 2004 00:03:12 +0000 (-0400) Subject: Re: [perl #31459] Bug in read() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6960c29afe6e3b12a2656bad7e38c80aa2c13fad;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #31459] Bug in read() Message-Id: <1094443392.12379.35.camel@linux.heathens.co.nz> a read(F) into a UTF8-encoded buffer with an offset off the end of the buffer, miss-calculated buffer lengths p4raw-id: //depot/perl@23321 --- diff --git a/pp_sys.c b/pp_sys.c index b615d4a..3071f1b 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1665,7 +1665,10 @@ PP(pp_sysread) } if (DO_UTF8(bufsv)) { /* convert offset-as-chars to offset-as-bytes */ - offset = utf8_hop((U8 *)buffer,offset) - (U8 *) buffer; + if (offset >= (int)blen) + offset += SvCUR(bufsv) - blen; + else + offset = utf8_hop((U8 *)buffer,offset) - (U8 *) buffer; } more_bytes: bufsize = SvCUR(bufsv);