#1068117 dieharder: dab_monobit2 crashes with ntuple > 17

Package:
dieharder
Source:
dieharder
Description:
Random-number generator test front-end
Submitter:
Lucas Thode
Date:
2024-04-09 02:36:03 UTC
Severity:
normal
#1068117#5
Date:
2024-03-31 03:47:23 UTC
From:
To:
Dear Maintainer,

`dieharder -d 209 -n $nvalue` crashes for $nvalue>17:

$ dieharder -d 209
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  1.55e+08  |2819069712|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  12|  65000000|       1|0.40510331|  PASSED
$ dieharder -d 209 -n 12
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  2.54e+08  | 152376536|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  12|  65000000|       1|0.10580971|  PASSED
$ dieharder -d 209 -n 17
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  2.29e+08  |2998370165|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  17|  65000000|       1|1.00000000|  FAILED
$ dieharder -d 209 -n 18
*** stack smashing detected ***: terminated
Aborted
$ dieharder -d 209 -n 27
*** stack smashing detected ***: terminated
Aborted
$ dieharder -d 209 -n 28
Segmentation fault

P.S. There are more issues with this test not liking non-standard n values, as
can be seen from it failing miserably on mt19937 with -n 17, but the crash is
the most glaring problem.

#1068117#10
Date:
2024-04-05 18:24:51 UTC
From:
To:
Hi Lucas,

On 30 March 2024 at 22:47, Lucas Thode wrote:
| Package: dieharder
| Version: 3.31.1.4-1.1
| Severity: normal
| X-Debbugs-Cc: thode.lj@gmail.com
|
| Dear Maintainer,
|
| `dieharder -d 209 -n $nvalue` crashes for $nvalue>17:
|
| $ dieharder -d 209
| #=============================================================================#
| #            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
| #=============================================================================#
|    rng_name    |rands/second|   Seed   |
|         mt19937|  1.55e+08  |2819069712|
| #=============================================================================#
|         test_name   |ntup| tsamples |psamples|  p-value |Assessment
| #=============================================================================#
|         dab_monobit2|  12|  65000000|       1|0.40510331|  PASSED
| $ dieharder -d 209 -n 12
| #=============================================================================#
| #            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
| #=============================================================================#
|    rng_name    |rands/second|   Seed   |
|         mt19937|  2.54e+08  | 152376536|
| #=============================================================================#
|         test_name   |ntup| tsamples |psamples|  p-value |Assessment
| #=============================================================================#
|         dab_monobit2|  12|  65000000|       1|0.10580971|  PASSED
| $ dieharder -d 209 -n 17
| #=============================================================================#
| #            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
| #=============================================================================#
|    rng_name    |rands/second|   Seed   |
|         mt19937|  2.29e+08  |2998370165|
| #=============================================================================#
|         test_name   |ntup| tsamples |psamples|  p-value |Assessment
| #=============================================================================#
|         dab_monobit2|  17|  65000000|       1|1.00000000|  FAILED
| $ dieharder -d 209 -n 18
| *** stack smashing detected ***: terminated
| Aborted
| $ dieharder -d 209 -n 27
| *** stack smashing detected ***: terminated
| Aborted
| $ dieharder -d 209 -n 28
| Segmentation fault
|
| P.S. There are more issues with this test not liking non-standard n values, as
| can be seen from it failing miserably on mt19937 with -n 17, but the crash is
| the most glaring problem.

Good stuff.

dieharder is a little 'dormant' upstream and via my maintenance of the Debian
package I have somewhat inherited upstream.  Can you take a look please if
this was take care of already at the (somewhat active) shadow repo of mine at

https://github.com/eddelbuettel/dieharder

I will also CC Milan who has been very attentive with a few other fixes, and
may have seen this one too.  We are trying to get hold of Robert but no luck
yet.

Cheers, Dirk

PS Apologies also for replying late. I usually get to bug reports within a
day but it's a teaching term plus being busy at my 'real job' puts some
stress on my response times.  :-/   I think I reply quicker to GH issues as I
am on GH all day anyway...


| -- System Information:
| Debian Release: trixie/sid
|   APT prefers testing
|   APT policy: (500, 'testing')
| Architecture: amd64 (x86_64)
| Foreign Architectures: i386
|
| Kernel: Linux 6.3.0-1-amd64 (SMP w/12 CPU threads; PREEMPT)
| Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
| Shell: /bin/sh linked to /usr/bin/dash
| Init: systemd (via /run/systemd/system)
| LSM: AppArmor: enabled
|
| Versions of packages dieharder depends on:
| ii  libc6             2.37-15
| ii  libdieharder3t64  3.31.1.4-1.1
| ii  libgsl27          2.7.1+dfsg-6+b1
|
| dieharder recommends no packages.
|
| dieharder suggests no packages.
|
| -- no debconf information

#1068117#15
Date:
2024-04-06 12:24:52 UTC
From:
To:
Hi,

the DAB Monobit2 test cannot use ntup higher thtn 15 due to the fixed allocations.

(It means it calculates data for block sizes up to 2^ntup blocks, so it make kind-of sense.)

I added check to prevent overflow, this is perhaps the best we can do here
(more details in description), see:

https://github.com/eddelbuettel/dieharder/pull/24

Milan

#1068117#20
Date:
2024-04-06 14:33:37 UTC
From:
To:
The updated version is still buggy, albeit in a different way, as it hangs
for n=18, fails the test for n=19, then segfaults for any n after that:

 ./dieharder/dieharder -d 209 -n 12 -p 1
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown
   #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  1.59e+08  |1346171031|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  12|  65000000|       1|0.31742526|  PASSED
$ ./dieharder/dieharder -d 209 -n 17 -p 1
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown
   #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  1.75e+08  |2063877943|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  17|  65000000|       1|1.00000000|  FAILED
$ ./dieharder/dieharder -d 209 -n 18 -p 1
^C
$ ./dieharder/dieharder -d 209 -n 19 -p 1
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown
   #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  1.78e+08  |2027322855|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  19|  65000000|       1|0.00000000|  FAILED
$ ./dieharder/dieharder -d 209 -n 20 -p 1
Segmentation fault
$ LD_LIBRARY_PATH=libdieharder/.libs gdb --args dieharder/.libs/dieharder
-d 209 -n 20 -p 1
(gdb) run
Starting program: ~/dieharder-test/dieharder/.libs/dieharder -d 209 -n 20
-p 1
Program received signal SIGSEGV, Segmentation fault.
add_2_test (dtest=0x3ff0000000000000, test=0x55555558a830, count=1)
    at std_test.c:233
233 for(j = 0;j < dtest->nkps;j++){
(gdb) bt
#0  add_2_test (dtest=0x3ff0000000000000, test=0x55555558a830, count=1)
    at std_test.c:233
#1  0x0000555555559bac in execute_test (dtest_num=209) at run_test.c:92
#2  0x0000555555559d82 in run_test () at run_test.c:32
#3  0x000055555555633e in main (argc=7, argv=0x7fffffffe078) at
dieharder.c:90

Unfortunately, the trail of what looks to be stack corruption goes cold
from there...

#1068117#25
Date:
2024-04-06 15:23:45 UTC
From:
To:
On 4/6/24 4:33 PM, Lucas Thode wrote:
...

Are you sure you run the patched version with patched libdieharder (and not one from system)?
You can avoid it by "./configure --disable-shared" to force static link.

This is what I get from current code
(https://github.com/eddelbuettel/dieharder):

./dieharder/dieharder -d 209 -n 17 -p 1
Error:  Can only use ntup up to 15.
         Read test description with dieharder -d 209 -h.

Milan

#1068117#30
Date:
2024-04-06 15:34:10 UTC
From:
To:
Even when built a statically linked libdieharder, I still get bogus results
(using yesterday's HEAD):
$ ldd dieharder/dieharder
linux-vdso.so.1 (0x00007ffe9b548000)
libgsl.so.27 => /lib/x86_64-linux-gnu/libgsl.so.27 (0x00007f28f3c00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f28f3b21000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f28f393f000)
libgslcblas.so.0 => /lib/x86_64-linux-gnu/libgslcblas.so.0
(0x00007f28f3ef2000)
/lib64/ld-linux-x86-64.so.2 (0x00007f28f4007000)
$ ./dieharder/dieharder -d 209 -n 17 -p 1
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown
   #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
        mt19937|  8.76e+07  | 422973324|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
        dab_monobit2|  17|  65000000|       1|0.00000000|  FAILED
$ ./dieharder/dieharder -d 209 -n 20 -p 1
Segmentation fault

#1068117#35
Date:
2024-04-06 15:46:10 UTC
From:
To:
Why yesterday's? The patch landed today. git pull?

The last patch in git log should be "Avoid overflow in DAB Monobit2 test."

With older code anything with -d 209 and -n over 15 corrupts memory and cannot get
any useful output.

Milan

#1068117#40
Date:
2024-04-06 22:32:27 UTC
From:
To:
Hi Lucas,

As Milan suggested, please sure you are current.  If in doubt, park you
current checkout and start from

    git checkout https://github.com/eddelbuettel/dieharder.git

where you should see today's commit from merging PR 24.

    edd@rob:~/git/dieharder(master)$ git ls | head
    *   3442896 - (HEAD -> master, origin/master, origin/HEAD) Merge pull request #24 from mbroz/dab-monobit2-ntup (10 hours ago) <Dirk Eddelbuettel>
    |\
    | * d928cbf - Avoid overflow in DAB Monobit2 test. (10 hours ago) <Milan Broz>
    |/
    *   2d4763a - Merge pull request #22 from mbroz/master (6 weeks ago) <Dirk Eddelbuettel>
    |\
    | * 67989b4 - Do not report file input rewind if nothing was read repeatedly. (6 weeks ago) <Milan Broz>
    |/
    * c987a15 - Fix segfault for wrongly specified test on commandline. (#21) (9 weeks ago) <Milan Broz>
    *   a186d90 - Merge pull request #20 from mbroz/warning-fixes (2 months ago) <Dirk Eddelbuettel>
    edd@rob:~/git/dieharder(master)$

Do not rely on the Debian package, it has not been updated yet.

Cheers, Dirk

#1068117#45
Date:
2024-04-08 23:21:21 UTC
From:
To:
Apologies for the confusion, I didn't realize the patch in question was a
new addition.  Just confirmed that it errors out instead of segfaulting or
hanging.

#1068117#50
Date:
2024-04-09 02:32:18 UTC
From:
To:
On 8 April 2024 at 18:21, Lucas Thode wrote:
| Apologies for the confusion, I didn't realize the patch in question was a new
| addition.  Just confirmed that it errors out instead of segfaulting or hanging.

Thanks for confirming!

Dirk

| On Sat, Apr 6, 2024 at 5:32 PM Dirk Eddelbuettel <edd@debian.org> wrote:
|
|
|     Hi Lucas,
|
|     As Milan suggested, please sure you are current.  If in doubt, park you
|     current checkout and start from
|
|         git checkout https://github.com/eddelbuettel/dieharder.git
|
|     where you should see today's commit from merging PR 24.
|
|         edd@rob:~/git/dieharder(master)$ git ls | head
|         *   3442896 - (HEAD -> master, origin/master, origin/HEAD) Merge pull
|     request #24 from mbroz/dab-monobit2-ntup (10 hours ago) <Dirk Eddelbuettel>
|         |\ 
|         | * d928cbf - Avoid overflow in DAB Monobit2 test. (10 hours ago)
|     <Milan Broz>
|         |/ 
|         *   2d4763a - Merge pull request #22 from mbroz/master (6 weeks ago)
|     <Dirk Eddelbuettel>
|         |\ 
|         | * 67989b4 - Do not report file input rewind if nothing was read
|     repeatedly. (6 weeks ago) <Milan Broz>
|         |/ 
|         * c987a15 - Fix segfault for wrongly specified test on commandline. (#
|     21) (9 weeks ago) <Milan Broz>
|         *   a186d90 - Merge pull request #20 from mbroz/warning-fixes (2 months
|     ago) <Dirk Eddelbuettel>
|         edd@rob:~/git/dieharder(master)$
|
|     Do not rely on the Debian package, it has not been updated yet.
|
|     Cheers, Dirk
|
|     --
|     dirk.eddelbuettel.com | @eddelbuettel | edd@debian.org
|
|