facebook / zstd

Zstandard - Fast real-time compression algorithm

Home Page:http://www.zstd.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZDICT_trainFromBuffer_cover is not thread safe

as-com opened this issue · comments

Describe the bug

ZDICT_trainFromBuffer_cover is not thread safe due to the use of global state:

/* We need a global context for qsort... */
static COVER_ctx_t *g_coverCtx = NULL;

Calling this function from multiple threads may result in segfault/access violation, use-after-free and other badness.

To Reproduce
Call ZDICT_trainFromBuffer_cover from multiple threads

Desktop (please complete the following information):

  • OS: Windows
  • Version 11 23H2
  • Compiler: MSVC, Visual Studio 2022
  • Flags: default
  • Other relevant hardware specs: N/A
  • Build system: whatever zstd-sys/cargo uses