zstd icon indicating copy to clipboard operation
zstd copied to clipboard

The dict trainer fails with SIGSEGV or floating point exception

Open luben opened this issue 2 years ago • 3 comments

Describe the bug The dict trainer fails with SIGSEGV or floating point exception

To Reproduce

  #include<zdict.h>
  #include<stdlib.h>

  const char * samples = "0123456789abcdefghij";
  const size_t sizes[20] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
  const size_t dict_size = 1024;
  const size_t n = 10;

  int main() {
      void * dict = malloc(dict_size);
      ZDICT_trainFromBuffer(dict, dict_size, samples, sizes, n);
  }

For n < 10 it fails with segmentation fault for n = 10 it fails with floating point exception

Expected behavior not to fail, returning error code for not being able to build a dict is expected also.

Desktop (please complete the following information):

  • OS: Linux, Ubuntu-20.4
  • Version: linux-5.15, libc6-2.31
  • Compiler: gcc (9, 10), clang-13
  • Build system: gcc -g -Wall -o zstd_test zstd_test.c -lzstd
  • zstd versions tested: 1.5.2 and 1.5.5

Additional context Reported in https://github.com/luben/zstd-jni/issues/253

luben avatar Apr 05 '23 05:04 luben