-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
randomPathName
called twice in a row can return the same string on windows
#17898
Labels
Comments
let's add secure random state for |
Using import times, std/sysrand
type
RandomState = enum
useTime, useSysrand
proc initRand(opt = useTime): Rand =
case opt
of useTime:
when defined(js):
let time = int64(times.epochTime() * 1000) and 0x7fff_ffff
result = initRand(time)
else:
let now = times.getTime()
result = initRand(convert(Seconds, Nanoseconds, now.toUnix) + now.nanosecond)
of useSysrand:
let state = urandom(8)
var num = 0'i64
for idx in 0 .. 7:
num += int64(state[idx]) shr (idx * 8'i64)
when defined(js):
result = initRand(num)
else:
result = initRand(num and 0x7fff_ffff) |
Maybe
|
ringabout
added a commit
to ringabout/Nim
that referenced
this issue
Apr 30, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 2, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 2, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 2, 2021
5 tasks
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 2, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 2, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 2, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 3, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 3, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 6, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Jun 6, 2021
ringabout
added a commit
to ringabout/Nim
that referenced
this issue
Jul 1, 2021
ringabout
added a commit
to ringabout/Nim
that referenced
this issue
Aug 22, 2021
Araq
pushed a commit
that referenced
this issue
Aug 22, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Aug 23, 2021
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Aug 23, 2021
PMunch
pushed a commit
to PMunch/Nim
that referenced
this issue
Mar 28, 2022
…e same string on windows) (nim-lang#18729) * close nim-lang#17898 * no need to consider js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is the 2nd bug with std/tempfiles i've encountered while working on #17892 (i already sent a fix for the 1st one #17888 which affected it). This shows that dog-fooding is useful and we should do more of it (ie, promote using stdlib within nim repo).
Example
Current Output
on windows, in CI,
echo diffStrings(lhs, rhs)
produced the following:(see also https://gist.github.com/timotheecour/515dde92cb29ce359a3f4b9546c247fd)
it looks like
randomPathName
produced the same stringC5xLA9E2
, and this is unlikely to be by accident.Expected Output
randomPathName
called twice in a row should return different strings with very high probability.Additional Information
1.5.1 1640508
I'm not on windows, but windows users should be able to minimize this issue with a reproducible example based on this, eg by calling
randomPathName
in a loop and checking for nearest neighbor duplicates/cc @xflywind can you reproduce this on your end?
The text was updated successfully, but these errors were encountered: