Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Bugs > Re: postmaster ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 7 Topic 3740 of 4089
Post > Topic >>

Re: postmaster segfault when using SELECT on a table

by Zdenek.Kotala@[EMAIL PROTECTED] (Zdenek Kotala) Apr 28, 2008 at 01:24 PM

This is a multi-part message in MIME format.

--Boundary_(ID_682ITD7Csu8ohi+VgbSe2Q)
Content-type: text/plain; format=flowed; charset=iso-8859-1
Content-transfer-encoding: 7BIT

Karsten Desler wrote:
> 
> I don't know much about the postgres architecture and I don't know if
bounds
> checking on-disk values on a read makes a lot of sense since usually one
> should be able to assume that there are no randomly flipped bits; but it
> would've been nice to have a sensible log entry as to what really
> happened.

I attached back****ted patch from head to 8.2. You can try it. It has small

performance penalty, but it does not crash on corrupted data.

		Zdenek

--Boundary_(ID_682ITD7Csu8ohi+VgbSe2Q)
Content-type: text/x-patch; name=pg_lzcompress.patch
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=pg_lzcompress.patch

*** src/backend/utils/adt/pg_lzcompress.c	2006/10/05 23:33:33	1.23
--- src/backend/utils/adt/pg_lzcompress.c	2008/03/08 01:09:36	1.31
*************** pglz_compress(const char *source, int32 
*** 631,656 ****
  void
  pglz_decompress(const PGLZ_Header *source, char *dest)
  {
! 	const unsigned char *dp;
! 	const unsigned char *dend;
! 	unsigned char *bp;
! 	unsigned char ctrl;
! 	int32		ctrlc;
! 	int32		len;
! 	int32		off;
! 	int32		destsize;
! 
! 	dp = ((const unsigned char *) source) + sizeof(PGLZ_Header);
! 	dend = ((const unsigned char *) source) + VARATT_SIZE(source);
! 	bp = (unsigned char *) dest;
  
! 	while (dp < dend)
  	{
  		/*
! 		 * Read one control byte and process the next 8 items.
  		 */
! 		ctrl = *dp++;
! 		for (ctrlc = 0; ctrlc < 8 && dp < dend; ctrlc++)
  		{
  			if (ctrl & 1)
  			{
--- 641,666 ----
  void
  pglz_decompress(const PGLZ_Header *source, char *dest)
  {
! 	const unsigned char *sp;
! 	const unsigned char *srcend;
! 	unsigned char *dp;
! 	unsigned char *destend;
! 
! 	sp = ((const unsigned char *) source) + sizeof(PGLZ_Header);
! 	srcend = ((const unsigned char *) source) + VARATT_SIZE(source);
! 	dp = (unsigned char *) dest;
! 	destend = dp + source->rawsize;
  
! 	while (sp < srcend && dp < destend)
  	{
  		/*
! 		 * Read one control byte and process the next 8 items (or as many
! 		 * as remain in the compressed input).
  		 */
! 		unsigned char ctrl = *sp++;
! 		int		ctrlc;
! 
! 		for (ctrlc = 0; ctrlc < 8 && sp < srcend; ctrlc++)
  		{
  			if (ctrl & 1)
  			{
*************** pglz_decompress(const PGLZ_Header *sourc
*** 661,671 ****
  				 * coded as 18, another extension tag byte tells how much
  				 * longer the match really was (0-255).
  				 */
! 				len = (dp[0] & 0x0f) + 3;
! 				off = ((dp[0] & 0xf0) << 4) | dp[1];
! 				dp += 2;
  				if (len == 18)
! 					len += *dp++;
  
  				/*
  				 * Now we copy the bytes specified by the tag from OUTPUT to
--- 671,697 ----
  				 * coded as 18, another extension tag byte tells how much
  				 * longer the match really was (0-255).
  				 */
! 				int32		len;
! 				int32		off;
! 
! 				len = (sp[0] & 0x0f) + 3;
! 				off = ((sp[0] & 0xf0) << 4) | sp[1];
! 				sp += 2;
  				if (len == 18)
! 					len += *sp++;
! 
! 				/*
! 				 * Check for output buffer overrun, to ensure we don't
! 				 * clobber memory in case of corrupt input.  Note: we must
! 				 * advance dp here to ensure the error is detected below
! 				 * the loop.  We don't simply put the elog inside the loop
! 				 * since that will probably interfere with optimization.
! 				 */
! 				if (dp + len > destend)
! 				{
! 					dp += len;
! 					break;
! 				}
  
  				/*
  				 * Now we copy the bytes specified by the tag from OUTPUT to
*************** pglz_decompress(const PGLZ_Header *sourc
*** 675,682 ****
  				 */
  				while (len--)
  				{
! 					*bp = bp[-off];
! 					bp++;
  				}
  			}
  			else
--- 701,708 ----
  				 */
  				while (len--)
  				{
! 					*dp = dp[-off];
! 					dp++;
  				}
  			}
  			else
*************** pglz_decompress(const PGLZ_Header *sourc
*** 685,691 ****
  				 * An unset control bit means LITERAL BYTE. So we just copy
  				 * one from INPUT to OUTPUT.
  				 */
! 				*bp++ = *dp++;
  			}
  
  			/*
--- 711,720 ----
  				 * An unset control bit means LITERAL BYTE. So we just copy
  				 * one from INPUT to OUTPUT.
  				 */
! 				if (dp >= destend)	/* check for buffer overrun */
! 					break;			/* do not clobber memory */
! 
! 				*dp++ = *sp++;
  			}
  
  			/*
*************** pglz_decompress(const PGLZ_Header *sourc
*** 696,709 ****
  	}
  
  	/*
! 	 * Check we decompressed the right amount, else die.  This is a FATAL
! 	 * condition if we tromped on more memory than expected (we assume we
! 	 * have not tromped on shared memory, though, so need not PANIC).
! 	 */
! 	destsize = (char *) bp - dest;
! 	if (destsize != source->rawsize)
! 		elog(destsize > source->rawsize ? FATAL : ERROR,
! 			 "compressed data is corrupt");
  
  	/*
  	 * That's it.
--- 725,734 ----
  	}
  
  	/*
! 	 * Check we decompressed the right amount.
! 	 */
! 	if (dp != destend || sp != srcend)
! 		elog(ERROR, "compressed data is corrupt");
  
  	/*
  	 * That's it.

--Boundary_(ID_682ITD7Csu8ohi+VgbSe2Q)
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

--Boundary_(ID_682ITD7Csu8ohi+VgbSe2Q)--
 




 7 Posts in Topic:
postmaster segfault when using SELECT on a table
kd@[EMAIL PROTECTED] (Ka  2008-04-26 12:39:06 
Re: postmaster segfault when using SELECT on a table
tgl@[EMAIL PROTECTED] (T  2008-04-26 13:24:56 
Re: postmaster segfault when using SELECT on a table
tgl@[EMAIL PROTECTED] (T  2008-04-26 15:29:32 
Re: postmaster segfault when using SELECT on a table
kd@[EMAIL PROTECTED] (Ka  2008-04-26 20:20:03 
Re: postmaster segfault when using SELECT on a table
Zdenek.Kotala@[EMAIL PROT  2008-04-28 13:24:58 
Re: postmaster segfault when using SELECT on a table
kd@[EMAIL PROTECTED] (Ka  2008-04-29 13:51:40 
Re: postmaster segfault when using SELECT on a table
Zdenek.Kotala@[EMAIL PROT  2008-04-28 13:31:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 10:33:34 CDT 2008.