Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKqKJ-0004r1-CQ for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Mar 2021 22:32:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lKqKI-000236-9m for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Mar 2021 22:32:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKqKI-0001uX-2J for pgsql-hackers@lists.postgresql.org; Fri, 12 Mar 2021 22:32:10 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lKqKA-0004Dz-LS for pgsql-hackers@postgresql.org; Fri, 12 Mar 2021 22:32:08 +0000 Received: by mail-ed1-x535.google.com with SMTP id dm8so10122611edb.2 for ; Fri, 12 Mar 2021 14:32:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=o/x+6wDtCOjmnye8Q7rQJ6dY+idHEqeJUtacdUs13rY=; b=TdbbARH0JOreKYnpo8y3CI5CLmumsapeZoperbZ2l+E3OcZ1s7rEI3l/B3BRTKFpCB k13507+zHdtv7zAIp+Et3gSTTo3DWYQRYSxN8YXnp4yo7WKSgGnLYTjkPsYoAo35Av/p YVWPipFXW0VVsvUOhTvTo1v1CcqYgInQj3NDuROVef0KovXjbs612SoCInuzWUXjpjFr flLXjbcKdwjvSksUZh/VNu8VDaDRgpfpaPDpeWt6XaN3t/bQT3s5pPQ6PX7Gx1fA+Q25 3o/xVSu1QJQN1q7gaRBfFrQhqVUdxPe1vMUSafAUwZhP55i9ZATxsXYvHUdXOnPbSjCE qoYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=o/x+6wDtCOjmnye8Q7rQJ6dY+idHEqeJUtacdUs13rY=; b=IV6buc/XStquE+vkcwhrt585ErXw1N1ctB1ZrVQcbdvln80nN/5SzhIX1JrBirphnE duoyTBrqONU09Tx+sFaDL10sFfPPce9nTwLORTSN1+PlZ0cTLR1DPeWUUCBV0b03PXcw sktB8lM+8CP0y8vcrllqkaeztSP4ba6qUqYSwlEMH6rIQKXdXShOml79errU2LMu8DIJ MrI59H7XEmTiszZlGhJbKDK5Tgs57erCigT7+6GoSYVYOEijIYFWJ9cAP5BeHoyIM23Y dXTsSA3IcI5TBj1huGn9i6ljAFnGW6PJqxi+582vZAhBp97JgS3wcnRnJQosTXgIPAu6 /RdQ== X-Gm-Message-State: AOAM532xD0+I1zj1xuEm6a80dsWwo822ZBLbRg7NiJ8xn55XbUNw2Tv0 xaaO0s6DeqIv2oeU7MBc0YPcafpwHfcy8S+EAswoaKhvOHHEKYkg0FwPn7c6yt7lRrIZlcUqJol lN/cFRKlbvhe3z6h423DW4YJwc+13vBmBsuy72m2z+pMPopY4nF/MJzzjL+ujDVhCG3nMDXOYQv lRnOpEfSpjx4BkG43XfWfYx8Lyo9nxkzaFV6VRxqHjLtroG/C6bveZlfbmANtqGpugGI+JeotRV uw6ntmsXsIp9B6MeCGIeJMSGUf0sFWgMcHo7g== X-Google-Smtp-Source: ABdhPJwqJARU7gL8hr9LeXmsRDmME7j8ZbLvH19W6Z4ZyffPBL73gcnMb1LdXu2amy4YnKaLI0pQzA== X-Received: by 2002:aa7:c9c9:: with SMTP id i9mr16517488edt.160.1615588320651; Fri, 12 Mar 2021 14:32:00 -0800 (PST) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id lx6sm3284583ejb.64.2021.03.12.14.31.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Mar 2021 14:31:59 -0800 (PST) Subject: Re: zstd compression for pg_dump To: Daniil Zakhlystov , Justin Pryzby , Andrey Borodin Cc: Tom Lane , pgsql-hackers References: <20201221194924.GI30237@telsasoft.com> <554920.1608580960@sss.pgh.pa.us> <20201222023235.GJ30237@telsasoft.com> <20210104025321.GA9712@telsasoft.com> <94586A5E-6A18-4EB7-B646-5249EC6FE266@yandex-team.ru> From: Tomas Vondra Message-ID: <3866daa6-cc68-2dbe-e7db-0478f1c3d21a@enterprisedb.com> Date: Fri, 12 Mar 2021 23:31:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <94586A5E-6A18-4EB7-B646-5249EC6FE266@yandex-team.ru> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/4/21 11:17 AM, Daniil Zakhlystov wrote: > Hi! > >> On Jan 4, 2021, at 11:04 AM, Andrey Borodin wrote: >> >> Daniil, is levels definition compatible with libpq compression patch? >> +typedef struct Compress { >> + CompressionAlgorithm alg; >> + int level; >> + /* Is a nondefault level set ? This is useful since different compression >> + * methods have different "default" levels. For now we assume the levels >> + * are all integer, though. >> + */ >> + bool level_set; >> +} Compress; > > Similarly to this patch, it is also possible to define the compression level at the initialization stage in libpq compression patch. > > The difference is that in libpq compression patch the default compression level always equal to 1, independently of the chosen compression algorithm. > >> On Jan 4, 2021, at 11:04 AM, Andrey Borodin wrote: >> >> Libpq compression encountered some problems with memory consumption which required some extra config efforts. > > >> On Jan 4, 2021, at 12:06 PM, Justin Pryzby wrote: >> >> RAM use is not significantly different from zlib, except that zstd --long adds >> more memory. > > Regarding ZSTD memory usage: > > Recently I’ve made a couple of tests of libpq compression with different ZLIB/ZSTD compression levels which shown that compressing/decompressing ZSTD w/ high compression levels > require to allocate more virtual (Commited_AS) memory, which may be exploited by malicious clients: > > https://www.postgresql.org/message-id/62527092-16BD-479F-B503-FA527AF3B0C2%40yandex-team.ru > > We can avoid high memory usage by limiting the max window size to 8MB. This should effectively disable the support of compression levels above 19: > https://www.postgresql.org/message-id/6A45DFAA-1682-4EF2-B835-C5F46615EC49%40yandex-team.ru > > So maybe it is worthwhile to use similar restrictions in this patch. > I think there's a big difference between those two patches. In the libpq case, the danger is that the client requests the server to compress the data in a way that requires a lot of memory. I.e. the memory is consumed on the server. With this pg_dump patch, the compression is done by the pg_dump process, not the server. So if the attacker configures the compression in a way that requires a lot of memory, so what? He'll just allocate memory on the client machine, where he could also just run a custom binary that does a huge malloc(). So I don't think we need to worry about this too much. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company