Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqVjS-0001qR-CA for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Aug 2018 03:47:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fqVjQ-0001KO-Hb for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Aug 2018 03:47:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqVjQ-0001Jv-5Q for pgsql-hackers@lists.postgresql.org; Fri, 17 Aug 2018 03:47:24 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fqVjL-0004Qj-US for pgsql-hackers@postgresql.org; Fri, 17 Aug 2018 03:47:23 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id EBF0E21C2908 for ; Fri, 17 Aug 2018 06:47:17 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.0.103] (unknown [5.79.139.210]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id AAD5621C2903 for ; Fri, 17 Aug 2018 06:47:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1534477637; bh=mQkye1HWJbUWJQQT9c5bUyg7w8+VsOzr++6fo2cuaZ8=; h=Reply-To:From:Subject:To:Date; b=jbZ3PfDFvGfemnUN2daIVFJCEHvanvcMAX5PmB1zlQfjbjdmFGEAGJzZdt/i1qlST +Pe9LAE8aLvyeTBl1LVREU+64b6QfBrNsu3goJHZelRQEXkMVRYWceWj69NixxGVap 2vGKu4s8R2/sVzzuClY06UcCcG1eBZAUzQCrTmcg= Reply-To: a.lepikhov@postgrespro.ru From: Andrey Lepikhov Subject: [PATCH] XLogReadRecord returns pointer to currently read page Organization: Postgres Professional To: PostgreSQL-Dev Message-ID: Date: Fri, 17 Aug 2018 08:47:15 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------D8C4D1E87F9ED6A81206B106" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------D8C4D1E87F9ED6A81206B106 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, hackers! I propose the patch for fix one small code defect. The XLogReadRecord() function reads the pages of a WAL segment that contain a WAL-record. Then it creates a readRecordBuf buffer in private memory of a backend and copy record from the pages to the readRecordBuf buffer. Pointer 'record' is set to the beginning of the readRecordBuf buffer. But if the WAL-record is fully placed on one page, the XLogReadRecord() function forgets to bind the "record" pointer with the beginning of the readRecordBuf buffer. In this case, XLogReadRecord() returns a pointer to an internal xlog page. This patch fixes the defect. Previously, in all cases of using WAL this was not a problem. However if you plan to perform some decoding operations before returning the WAL record to the caller (this is my case), this can lead to bugs that are difficult to catch. -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company --------------D8C4D1E87F9ED6A81206B106 Content-Type: text/x-patch; name="0001-WAL-record-local-buffer-pointer-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-WAL-record-local-buffer-pointer-fix.patch" From 0a7d7bf07eb91a959b2864a7497088c4d203aaa4 Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Fri, 17 Aug 2018 07:56:30 +0500 Subject: [PATCH] WAL record local buffer pointer fix --- src/backend/access/transam/xlogreader.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 4c633c6c49..7bccc68189 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -480,6 +480,7 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) state->ReadRecPtr = RecPtr; memcpy(state->readRecordBuf, record, total_len); + record = (XLogRecord *) state->readRecordBuf; } /* -- 2.17.1 --------------D8C4D1E87F9ED6A81206B106--