From: Tom Lane <tgl@sss.pgh.pa.us>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: Dilip Kumar <dilipbalaut@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Alexander Korotkov <a.korotkov@postgrespro.ru>
Cc: David Steele <david@pgmasters.net>
Cc: Ildus Kurbangaliev <i.kurbangaliev@gmail.com>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: Andrey Borodin <x4mmm@yandex-team.ru>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: [HACKERS] Custom compression methods (mac+lz4.h)
Date: Sun, 21 Mar 2021 19:52:09 -0400
Message-ID: <507597.1616370729@sss.pgh.pa.us> (raw)
In-Reply-To: <20210321234324.GC4203@telsasoft.com>
References: <301730.1616276227@sss.pgh.pa.us>
<20210320231957.GX11765@telsasoft.com>
<309337.1616287493@sss.pgh.pa.us>
<311370.1616290403@sss.pgh.pa.us>
<CAFiTN-tN-fi=9VEatyiZyhW28yhhQCmn-egYzbdxBTLkOnVQvg@mail.gmail.com>
<CAFiTN-t0w+Rc2U3S+y=7KWcLuOYNB5MfWeGdNa7+pg0UovVdcQ@mail.gmail.com>
<414943.1616358751@sss.pgh.pa.us>
<20210321204148.GB4203@telsasoft.com>
<456616.1616360715@sss.pgh.pa.us>
<504396.1616368310@sss.pgh.pa.us>
<20210321234324.GC4203@telsasoft.com>
Justin Pryzby <pryzby@telsasoft.com> writes:
> On Sun, Mar 21, 2021 at 07:11:50PM -0400, Tom Lane wrote:
>> I hate to be the bearer of bad news, but this suggests that
>> LZ4_decompress_safe_partial is seriously broken in 1.9.2
>> as well:
>> https://github.com/lz4/lz4/issues/783> Ouch
Actually, after reading that closer, the problem only affects the
case where the compressed-data-length passed to the function is
a lie. So it shouldn't be a problem for our usage.
Also, after studying the documentation for LZ4_decompress_safe
and LZ4_decompress_safe_partial, I realized that liblz4 is also
counting on the *output* buffer size to not be a lie. So we
cannot pass it a number larger than the chunk's true decompressed
size. The attached patch resolves the issue I'm seeing.
regards, tom lane
Attachments:fix-partial-lz4-decompression.patch (text/x-diff, 682B) downloaddiff --git a/src/backend/access/common/toast_compression.c b/src/backend/access/common/toast_compression.cindex 00af1740cf..74e449992a 100644--- a/src/backend/access/common/toast_compression.c+++ b/src/backend/access/common/toast_compression.c@@ -220,6 +220,10 @@ lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength)
if (LZ4_versionNumber() < 10803)
return lz4_decompress_datum(value);
+ /* liblz4 assumes that slicelength is not an overestimate */+ if (slicelength >= VARRAWSIZE_4B_C(value))+ return lz4_decompress_datum(value);+
/* allocate memory for the uncompressed data */
result = (struct varlena *) palloc(slicelength + VARHDRSZ);
=
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pryzby@telsasoft.com, dilipbalaut@gmail.com, robertmhaas@gmail.com, andres@anarazel.de, tomas.vondra@2ndquadrant.com, a.korotkov@postgrespro.ru, david@pgmasters.net, i.kurbangaliev@gmail.com, 9erthalion6@gmail.com, x4mmm@yandex-team.ru, pgsql-hackers@lists.postgresql.org
Subject: Re: [HACKERS] Custom compression methods (mac+lz4.h)
In-Reply-To: <507597.1616370729@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox