Bug #6990
closedtest_s_random_bytes_without_openssl error on Windows x64
Description
=begin
TestSecureRandom sometimes has an error on ci.rubyinstaller.
http://ci.rubyinstaller.org/job/ruby-trunk-x64-test-all/41/console
- Error:
test_s_random_bytes_without_openssl(TestSecureRandom):
SystemCallError: unknown error - CryptGenRandom failed: The parameter is incorrect.
C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/lib/securerandom.rb:116:inrandom_bytes' C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/test/test_securerandom.rb:12:in
test_s_random_bytes'
C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/test/test_securerandom.rb:97:inblock in test_s_random_bytes_without_openssl' C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/lib/tmpdir.rb:88:in
mktmpdir'
C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/test/test_securerandom.rb:85:in `test_s_random_bytes_without_openssl'
This error seems to occur only on x64.
I guess the following scenario.
Pointer size of @hProv seems limited to 32bit with x64 ruby.
If the pointer value was larger than 32bit max, it would fail.
https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L106
I don't get the error at test-all on my local box, but I can get same error with the following script.
It takes long time to get the error.
require "openssl"
OpenSSL.send(:remove_const, :Random)
require "securerandom"
i = 0
loop do
SecureRandom.random_bytes
SecureRandom.send(:remove_instance_variable, :@has_win32)
p SecureRandom.send(:instance_variable_get, :@hProv).to_s(16) if (i % 10000) == 0
i += 1
end
I attached a patch. I also fixed encoding error which occurs if error message contains Japanese characters.
=end
Files