This patch should fix the problem. Doesn't include my previous patch
authorBruce Momjian
Thu, 22 Aug 2002 04:55:05 +0000 (04:55 +0000)
committerBruce Momjian
Thu, 22 Aug 2002 04:55:05 +0000 (04:55 +0000)
for repeat(). Again, somewhat off-the-cuff, so I might have missed
something...

test=# select lpad('xxxxx',1431655765,'yyyyyyyyyyyyyyyy');
ERROR:  Requested length too large
test=# select rpad('xxxxx',1431655765,'yyyyyyyyyyyyyyyy');
ERROR:  Requested length too large

(That's on a Unicode DB, haven't tested other encodings but AFAICT
this fix should still work.)

Neil Conway

src/backend/utils/adt/oracle_compat.c

index dfeb18c551bff90cdf14c76639d06c7b91512b78..6236d74c9d450b408c259c0cc2265e79736a4ab1 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.39 2002/08/22 04:54:20 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.40 2002/08/22 04:55:05 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -199,6 +199,11 @@ lpad(PG_FUNCTION_ARGS)
 
 #ifdef MULTIBYTE
    bytelen = pg_database_encoding_max_length() * len;
+
+   /* check for integer overflow */
+   if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
+       elog(ERROR, "Requested length too large");
+
    ret = (text *) palloc(VARHDRSZ + bytelen);
 #else
    ret = (text *) palloc(VARHDRSZ + len);
@@ -310,6 +315,11 @@ rpad(PG_FUNCTION_ARGS)
 
 #ifdef MULTIBYTE
    bytelen = pg_database_encoding_max_length() * len;
+
+   /* Check for integer overflow */
+   if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
+       elog(ERROR, "Requested length too large");
+
    ret = (text *) palloc(VARHDRSZ + bytelen);
 #else
    ret = (text *) palloc(VARHDRSZ + len);