From: Chris Heath Date: Mon, 6 Sep 2004 00:03:12 +0000 (-0400) Subject: Re: [perl #31459] Bug in read() X-Git-Tag: upstream/5.16.3~21649 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6960c29afe6e3b12a2656bad7e38c80aa2c13fad;p=platform%2Fupstream%2Fperl.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 b615d4ab5f..3071f1bfea 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);