Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iOU3P-0005X5-Sy for pgsql-bugs@arkaria.postgresql.org; Sat, 26 Oct 2019 21:57:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iOU3O-0006Gf-3w for pgsql-bugs@arkaria.postgresql.org; Sat, 26 Oct 2019 21:56:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iOU3N-0006GG-M7 for pgsql-bugs@lists.postgresql.org; Sat, 26 Oct 2019 21:56:57 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iOU3G-0002px-C5 for pgsql-bugs@lists.postgresql.org; Sat, 26 Oct 2019 21:56:56 +0000 Received: by mail-wr1-x444.google.com with SMTP id v9so6041035wrq.5 for ; Sat, 26 Oct 2019 14:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DnnmA8oGBC/BGrsy7wrXfqpBZOggJlETH0PmURbaV1Q=; b=lv70irnIk4kgenykFvr/DQ48gbvRNRZELGyXxDxOXKX5M2npeeYEiUCIbwiw+SAeQS TQdbBNA0JvYhkNEmHlwdtfa+Vp5HxoUIx/BJZnQ1yeaz69+qiUioAYhndjiU0GW1mAQb 3/rtpXvVB+uEt5NKi3xx+MG2QcrFtjuav1HyK8d5/lD+GGdgEParPuevOvA/aL6VzOS0 t0zCUSQYy3CfKNTVApmLT5oxNydZEyOo50YyGAufen6YQMxg+nU9//1ZsJ+/r+42b0od RKmgAH2p/VStmZMbMIj5dwOwT3vhIKtmW54ofXCRflVSCHq4vPudkGw29JmUmuTTwNAm Fr8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=DnnmA8oGBC/BGrsy7wrXfqpBZOggJlETH0PmURbaV1Q=; b=bKlFx1LQd9zt0CYWGP3u79MwmnuOarBeQxbXQ3OrkaZxb3puJkjbREz8OGfs9A+ogk ZexpRUIJy/ZYzRUWAp8GtiemWLp+mQCGRBjDjLQBYXli8fYC5HSLC666jcA/yR+jaHqD oNitD9diPI6csteQzYRHRAAqgs9c+9hNzZ61u6u3TQwiwTn+R1ZxwuDx/bJTO1FfWXIX cxwzya0YEc7r6cjbmJhEC84ney5jemeDiRAPB1IVdZpQej3hugtHbcNcoHtXKQa2Rskk NGz0sB1zhTPEl8dqTcsV3rV3yqAjGZ9dOwMZtcJjnCh0wuAZVZHbV49RTxOLNSTJHJAM fo6Q== X-Gm-Message-State: APjAAAUE05VqxHhg2kFZQub2hHXWATH0DaUmB8Q0JU3i1kjhAv0z05iO B5j1+ir0RY8Dj4sNWTGKwHJNng== X-Google-Smtp-Source: APXvYqwbObHAkiOck1tyv29wOcqerjaasRbcOVCmX1WvpB+v65OUoHpJAgT9JV0drqaRjQ2Zpex+NQ== X-Received: by 2002:a5d:54c7:: with SMTP id x7mr8301113wrv.99.1572127007911; Sat, 26 Oct 2019 14:56:47 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id 17sm5771357wmg.29.2019.10.26.14.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2019 14:56:47 -0700 (PDT) Date: Sat, 26 Oct 2019 23:56:46 +0200 From: Tomas Vondra To: cilizili@protonmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16082: TOAST's pglz_decompress access to uninitialized data, if the database is corrupted. Message-ID: <20191026215646.5e2brazqzboxclf4@development> References: <16082-96c2ec8be45150cb@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <16082-96c2ec8be45150cb@postgresql.org> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Oct 26, 2019 at 07:46:25AM +0000, PG Bug reporting form wrote: >The following bug has been logged on the website: > >Bug reference: 16082 >Logged by: cili >Email address: cilizili@protonmail.com >PostgreSQL version: 12.0 >Operating system: Microsoft Windows [Version 10.0.18362.418] >Description: > >The function pglz_decompress in src/common/pglz_decompress.c may refer >invalid data in the corrupted database file. >I show you two bad cases along with corrupted database file, and how to >make. > >The first byte of TOAST structure is a control byte. If the LSB of control >byte is set, the 2nd byte is the length and the 3rd byte is an offset of >repeating bytes in dest block. >There is two case that they are valid for invalid data. In the case 1, it >reads an uninitialized data in the dest. In the case 2, it reads >uninitialized or out-of-bound data in the dest. They are invalid. >I'll show you the setup and one normal case, and then show two bad bug >cases. > Well, failure like this after reading corrupted data from disk is not really surprising and it's hardly a bug. It's kinda intended to work that way, really. Essentially, if something outside PostgreSQL corrupted the data file, then all bets are off. We have a protection against that in the form of data checksums, in which case we'd (very probably) identify that while reading the page from disk. If the page was corrupted by PostgreSQL itself, we might not notice that, but then the thing that corrupted the data file is the bug, not that pglz_decompress fails. But AFAICS you have not demonstrated any such data corruption issue, you assume the data file is corrupted by something outside PostgreSQL (i.e. the first case). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services