Re: [perl #31459] Bug in read()
authorChris Heath <chris@heathens.co.nz>
Mon, 6 Sep 2004 00:03:12 +0000 (20:03 -0400)
committerDave Mitchell <davem@fdisolutions.com>
Tue, 14 Sep 2004 21:57:10 +0000 (21:57 +0000)
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

pp_sys.c

index b615d4ab5f9546e251e5fa5918733abe77cecd7b..3071f1bfeabdb2dbfe1d10d824f9dadd798e21b1 100644 (file)
--- 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);