Skip to content

Commit d86dee3

Browse files
committed
This patch should fix the problem. Doesn't include my previous patch
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
1 parent cbe733d commit d86dee3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/backend/utils/adt/oracle_compat.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.39 2002/08/22 04:54:20 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.40 2002/08/22 04:55:05 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -199,6 +199,11 @@ lpad(PG_FUNCTION_ARGS)
199199

200200
#ifdef MULTIBYTE
201201
bytelen = pg_database_encoding_max_length() * len;
202+
203+
/* check for integer overflow */
204+
if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
205+
elog(ERROR, "Requested length too large");
206+
202207
ret = (text *) palloc(VARHDRSZ + bytelen);
203208
#else
204209
ret = (text *) palloc(VARHDRSZ + len);
@@ -310,6 +315,11 @@ rpad(PG_FUNCTION_ARGS)
310315

311316
#ifdef MULTIBYTE
312317
bytelen = pg_database_encoding_max_length() * len;
318+
319+
/* Check for integer overflow */
320+
if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
321+
elog(ERROR, "Requested length too large");
322+
313323
ret = (text *) palloc(VARHDRSZ + bytelen);
314324
#else
315325
ret = (text *) palloc(VARHDRSZ + len);

0 commit comments

Comments
 (0)