Project

General

Profile

Actions

Bug #6990

closed

test_s_random_bytes_without_openssl error on Windows x64

Added by h.shirosaki (Hiroshi Shirosaki) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2012-09-06 trunk 36917) [x64-mingw32]
Backport:
[ruby-core:47451]

Description

=begin

TestSecureRandom sometimes has an error on ci.rubyinstaller.

http://ci.rubyinstaller.org/job/ruby-trunk-x64-test-all/41/console

  1. 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:in random_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:in block 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

fix_securerandom_x64.patch (1.35 KB) fix_securerandom_x64.patch h.shirosaki (Hiroshi Shirosaki), 09/07/2012 07:36 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0