Index: contrib/txid/txid.c
===================================================================
RCS file: /projects/cvsroot/pgsql/contrib/txid/txid.c,v
retrieving revision 1.1
diff -p -u -c -r1.1 txid.c
*** contrib/txid/txid.c	7 Oct 2007 23:32:19 -0000	1.1
--- contrib/txid/txid.c	8 Oct 2007 19:38:02 -0000
*************** buf_finalize(StringInfo buf)
*** 226,231 ****
--- 226,262 ----
  }
  
  /*
+  * simple number parser.
+  *
+  * return 0 on error, which is invalid value fot txid.
+  */
+ static txid
+ str2txid(const char *s, const char **endp)
+ {
+ 	txid val = 0, last = 0;
+ 
+ 	for (; *s; s++)
+ 	{
+ 		if (*s < '0' || *s > '9')
+ 			break;
+ 
+ 		val = val * 10 + (*s - '0');
+ 
+ 		/*
+ 		 * check for overflow
+ 		 */
+ 		if (val > MAX_TXID || val < last) {
+ 			val = 0;
+ 			break;
+ 		}
+ 		last = val;
+ 	}
+ 	if (endp)
+ 		*endp = s;
+ 	return val;
+ }
+ 
+ /*
   * parse snapshot from cstring
   */
  static TxidSnapshot *
*************** parse_snapshot(const char *str)
*** 234,248 ****
  	txid		xmin;
  	txid		xmax;
  	txid		last_val = 0, val;
! 	char	   *endp;
  	StringInfo  buf;
  
! 	xmin = (txid) strtoull(str, &endp, 0);
  	if (*endp != ':')
  		goto bad_format;
  	str = endp + 1;
  
! 	xmax = (txid) strtoull(str, &endp, 0);
  	if (*endp != ':')
  		goto bad_format;
  	str = endp + 1;
--- 265,279 ----
  	txid		xmin;
  	txid		xmax;
  	txid		last_val = 0, val;
! 	const char *endp;
  	StringInfo  buf;
  
! 	xmin = str2txid(str, &endp);
  	if (*endp != ':')
  		goto bad_format;
  	str = endp + 1;
  
! 	xmax = str2txid(str, &endp);
  	if (*endp != ':')
  		goto bad_format;
  	str = endp + 1;
*************** parse_snapshot(const char *str)
*** 258,264 ****
  	while (*str != '\0')
  	{
  		/* read next value */
! 		val = (txid) strtoull(str, &endp, 0);
  		str = endp;
  
  		/* require the input to be in order */
--- 289,295 ----
  	while (*str != '\0')
  	{
  		/* read next value */
! 		val = str2txid(str, &endp);
  		str = endp;
  
  		/* require the input to be in order */
Index: contrib/txid/expected/txid.out
===================================================================
RCS file: /projects/cvsroot/pgsql/contrib/txid/expected/txid.out,v
retrieving revision 1.1
diff -p -u -c -r1.1 txid.out
*** contrib/txid/expected/txid.out	7 Oct 2007 23:32:19 -0000	1.1
--- contrib/txid/expected/txid.out	8 Oct 2007 19:38:02 -0000
*************** select txid_visible_in_snapshot('1000100
*** 210,212 ****
--- 210,221 ----
   t
  (1 row)
  
+ -- test 64bit overflow
+ SELECT txid_snapshot '1:9223372036854775807:3';
+       txid_snapshot      
+ -------------------------
+  1:9223372036854775807:3
+ (1 row)
+ 
+ SELECT txid_snapshot '1:9223372036854775808:3';
+ ERROR:  illegal txid_snapshot input format
Index: contrib/txid/sql/txid.sql
===================================================================
RCS file: /projects/cvsroot/pgsql/contrib/txid/sql/txid.sql,v
retrieving revision 1.1
diff -p -u -c -r1.1 txid.sql
*** contrib/txid/sql/txid.sql	7 Oct 2007 23:32:19 -0000	1.1
--- contrib/txid/sql/txid.sql	8 Oct 2007 19:38:02 -0000
*************** select txid_snapshot '1000100010001000:1
*** 56,58 ****
--- 56,62 ----
  select txid_visible_in_snapshot('1000100010001012', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');
  select txid_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');
  
+ -- test 64bit overflow
+ SELECT txid_snapshot '1:9223372036854775807:3';
+ SELECT txid_snapshot '1:9223372036854775808:3';
+ 
