Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQ1A0-0006f5-TW for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jul 2016 23:44:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bQ1A0-0008PG-8t for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jul 2016 23:44:16 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bQ19y-0008KK-3u for pgsql-hackers@postgresql.org; Wed, 20 Jul 2016 23:44:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bQ19v-00069Z-5f for pgsql-hackers@postgresql.org; Wed, 20 Jul 2016 23:44:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u6KNi7kG011036; Wed, 20 Jul 2016 19:44:07 -0400 From: Tom Lane To: Andres Freund cc: pgsql-hackers@postgresql.org Subject: Re: skink's test_decoding failures in 9.4 branch In-reply-to: <20160720170159.i7ctvb3i6ut3aref@alap3.anarazel.de> References: <17922.1469030757@sss.pgh.pa.us> <21842.1469033104@sss.pgh.pa.us> <20160720170159.i7ctvb3i6ut3aref@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Wed, 20 Jul 2016 10:01:59 -0700" Date: Wed, 20 Jul 2016 19:44:07 -0400 Message-ID: <11035.1469058247@sss.pgh.pa.us> X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andres Freund writes: > I guess either using valgrind's gdb server on error, or putting some > asserts checking the size would be best. I can look into it, but it'll > not be today likely. I believe the problem is that DecodeUpdate is not on the same page as the WAL-writing routines about how much data there is for an old_key_tuple. Specifically, I see this in 9.4's log_heap_update(): if (old_key_tuple) { ... xlhdr_idx.t_len = old_key_tuple->t_len; rdata[nr].data = (char *) old_key_tuple->t_data + offsetof(HeapTupleHeaderData, t_bits); rdata[nr].len = old_key_tuple->t_len - offsetof(HeapTupleHeaderData, t_bits); ... } so that the amount of tuple data that's *actually* in WAL is offsetof(HeapTupleHeaderData, t_bits) less than what t_len says. However, over in DecodeUpdate, this is processed with xl_heap_header_len xlhdr; memcpy(&xlhdr, data, sizeof(xlhdr)); ... datalen = xlhdr.t_len + SizeOfHeapHeader; ... DecodeXLogTuple(data, datalen, change->data.tp.oldtuple); and what DecodeXLogTuple does is int datalen = len - SizeOfHeapHeader; (so we're back to datalen == xlhdr.t_len) ... memcpy(((char *) tuple->tuple.t_data) + offsetof(HeapTupleHeaderData, t_bits), data + SizeOfHeapHeader, datalen); so that we are copying offsetof(HeapTupleHeaderData, t_bits) too much data from the WAL buffer. Most of the time this doesn't hurt but it's making valgrind complain, and on a unlucky day we might crash entirely. I have not looked to see if the bug also exists in > 9.4. Also, it's not very clear to me whether other call sites for DecodeXLogTuple might have related bugs. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers