Skip to content

Commit 593b89d

Browse files
committed
Add max window size limit
1 parent e17a342 commit 593b89d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/common/zpq_stream.c

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ struct ZpqStream
7070
#include <zstd.h>
7171

7272
#define ZSTD_BUFFER_SIZE (8*1024)
73+
/*
74+
* Maximum allowed back-reference distance, expressed as power of 2.
75+
* This setting controls max compressor/decompressor window size.
76+
* More details https://github.com/facebook/zstd/blob/v1.4.7/lib/zstd.h#L536
77+
*/
78+
#define ZSTD_WINDOWLOG_LIMIT 23 /* set max window size to 8MB */
7379

7480
typedef struct ZstdStream
7581
{
@@ -100,8 +106,10 @@ zstd_create(int level, zpq_tx_func tx_func, zpq_rx_func rx_func, void *arg, char
100106

101107
zs->tx_stream = ZSTD_createCStream();
102108
ZSTD_initCStream(zs->tx_stream, level);
109+
ZSTD_CCtx_getParameter(zs->tx_stream, ZSTD_c_windowLog, ZSTD_WINDOWLOG_LIMIT);
103110
zs->rx_stream = ZSTD_createDStream();
104111
ZSTD_initDStream(zs->rx_stream);
112+
ZSTD_DCtx_setParameter(zs->rx_stream, ZSTD_d_windowLogMax, ZSTD_WINDOWLOG_LIMIT);
105113
zs->tx.dst = zs->tx_buf;
106114
zs->tx.pos = 0;
107115
zs->tx.size = ZSTD_BUFFER_SIZE;

0 commit comments

Comments
 (0)