Open inaimathi opened 9 years ago
Cannot reproduce in CCL 1.10 on Linux—and don't have Windows to test this myself. The integer 34950810361856 requires 45-bits, however—can you identify in the backtrace where it's coming from (more specifically than somewhere in generate-next-isaac-block
)?
Also, which versions of Windows and CCL has this appeared?
It's CCL 1.09-r15764
, running on Windows 7 SP1. I can't be much more specific, sadly; I only know that it happens somewhere in the loop body, and it seems to consistently hit at either i=2
or i=4
.
Would you be able to take a sample from CCL 1.09-r15764 of (random (ash 1 32))
and test each value r
with (integer-length r)
, and let me know if any of the integer-length values exceed 32-bits, and how many of them do? A sample-size of 10,000 should be fine.
Hm.
Looks like
CL-USER> (loop repeat 100000 for r = (random (ash 1 32))
when (> (integer-length r) 32)
collect (list r (integer-length r)))
NIL
CL-USER>
That is an intentional 100,000 in the repeat
clause. I then loaded in cl-isaac
and tried to eval init-common-lisp-random-seed
; it still gives me the same UNSIGNED-BYTE
error I mention in the bug report.
Anything else I could try?
Hmmm. Try fiddling with logxor
and logand
of #xFFFFFFFF
to r
, in the above loop? It looks like one of the values it's trying to assign to slots A, B, and C on ISAAC-CTX are too large. The value should never exceed the order of #xFFFFFFFF
.
Another point of issue could be the use of (the (unsigned-byte 32))
. Could you experiment with CCL's handling of that with a manually built context?
Also, does the same error happen on CCL 1.10, on Windows?
I encounter the same problem on recentish (~2 months old?) SBCL. The problem occurs in this line. https://github.com/thephoeron/cl-isaac/blob/938318303d31a7be886ce3b68b427b087d519d90/isaac-32.lisp#L28
Note that because I restrict my compiler policy in my RC file, the code is compiled with different optimize settings than the default.
(sb-ext:restrict-compiler-policy 'debug 1)
(sb-ext:restrict-compiler-policy 'safety 1)
I fixed the issue by moving the type assertion after performing the bitmasking. This seems correct as we can't guarantee that the result of shifting an (unsigned-byte 32)
is another (unsigned-byte 32)
. I.e.
...
(logxor (isaac-ctx-a ctx)
(the (unsigned-byte 32)
(logand #xFFFFFFFF
(ash (isaac-ctx-a ctx)
(ecase (logand i 3)
((0) 13)
((1) -6)
((2) 2)
((3) -16))))))
...
I encountered the problem trying to use https://github.com/inaimathi/session-token.
(session-token:init-kernel-seed)
@PuercoPop thanks for letting me know! That's a good point about guaranteeing the result of the shift.
Steps to reproduce:
ccl
cl-isaac
Here's my repl session:
and here's the error dump