This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[Patch Encode.xs] calculation of need overflows
authorSADAHIRO Tomoyuki <BQW10602@nifty.com>
Sat, 26 Jan 2002 00:58:50 +0000 (09:58 +0900)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 25 Jan 2002 17:25:05 +0000 (17:25 +0000)
Message-Id: <20020126005802.89B3.BQW10602@nifty.com>

p4raw-id: //depot/perl@14419

ext/Encode/Encode.xs

index ba7935e..27097e7 100644 (file)
@@ -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;