From: SADAHIRO Tomoyuki Date: Sat, 26 Jan 2002 00:58:50 +0000 (+0900) Subject: [Patch Encode.xs] calculation of need overflows X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6fa35b067dd6fd8e20b4b357a4dc01750b05b084;p=p5sagit%2Fp5-mst-13.2.git [Patch Encode.xs] calculation of need overflows Message-Id: <20020126005802.89B3.BQW10602@nifty.com> p4raw-id: //depot/perl@14419 --- diff --git a/ext/Encode/Encode.xs b/ext/Encode/Encode.xs index ba7935e..27097e7 100644 --- a/ext/Encode/Encode.xs +++ b/ext/Encode/Encode.xs @@ -409,10 +409,12 @@ encode_method(pTHX_ encode_t *enc, encpage_t *dir, SV *src, int check) { case ENCODE_NOSPACE: { - STRLEN need = (slen) ? (SvLEN(dst)*SvCUR(src)/slen) : (dlen + UTF8_MAXLEN); - if (need <= SvLEN(dst)) - need += UTF8_MAXLEN; + STRLEN need = dlen + UTF8_MAXLEN * 128; /* 128 is too big or small? */ d = (U8 *) SvGROW(dst, need); + if (dlen >= SvLEN(dst)) + { + Perl_croak(aTHX_ "Destination couldn't be grown (the need may be miscalculated)."); + } dlen = SvLEN(dst); slen = SvCUR(src); break;