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

Ruby 2.2 64bit / Pageant / Windows / "bignum too big to convert into `long'" #235

Closed
ccoenen opened this Issue Apr 2, 2015 · 16 comments

Comments

Projects
None yet
9 participants
@ccoenen

ccoenen commented Apr 2, 2015

This issue is exclusive to the 64 bit build of ruby 2.2.1. The 32bit build runs fine.

The current master (3ed5b19) won't work on ruby 2.2.1-64 / Windows. It fails with this message:

SSHKit::Runner::ExecuteError: Exception while executing on host --redacted--: bignum too big to convert into `long'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:191:in `malloc'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:191:in `malloc_ptr'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:255:in `get_token_information'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:228:in `get_current_user'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:204:in `get_security_attributes_for_user'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:347:in `send_query'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/pageant.rb:324:in `send'
C:/Tools/Ruby22-x64/lib/ruby/gems/2.2.0/bundler/gems/net-ssh-3ed5b1963c1a/lib/net/ssh/authentication/agent/socket.rb:148:in `send_packet'

There has been some work towards 2.2 compatibility in January, so i wonder if this should actually be working or if it was not tested on 64 bit.

The latest release (v2.9.2 at the time of writing) does not work because of the removal of 'dl' in ruby 2.2.

@ccoenen

This comment has been minimized.

Show comment
Hide comment
@ccoenen

ccoenen Apr 7, 2015

It would also be very nice to have the current master as a release (even if only 32bit works on windows), so that we don't need to pull it in from github.

ccoenen commented Apr 7, 2015

It would also be very nice to have the current master as a release (even if only 32bit works on windows), so that we don't need to pull it in from github.

@Antiarchitect

This comment has been minimized.

Show comment
Hide comment
@Antiarchitect

Antiarchitect Apr 21, 2015

+1 Experiencing exact the same issue.

Antiarchitect commented Apr 21, 2015

+1 Experiencing exact the same issue.

@pleaseking

This comment has been minimized.

Show comment
Hide comment
@pleaseking

pleaseking Apr 24, 2015

This pull request is supposed to fix it: #239

pleaseking commented Apr 24, 2015

This pull request is supposed to fix it: #239

@thargor

This comment has been minimized.

Show comment
Hide comment
@thargor

thargor Jun 24, 2015

This bug is not fixed in #239 (or at least not working in v2.10.0.beta1)

thargor commented Jun 24, 2015

This bug is not fixed in #239 (or at least not working in v2.10.0.beta1)

@sschuberth

This comment has been minimized.

Show comment
Hide comment
@sschuberth

sschuberth Jul 13, 2015

Contributor

I'm unable to reproduce this with current master (bab0318) on Windows 8.1 x64, Ruby 2.2.2 x64, using Pageant for authentication. If anyone still sees this, could you please post a minimal program to trigger this issue?

Contributor

sschuberth commented Jul 13, 2015

I'm unable to reproduce this with current master (bab0318) on Windows 8.1 x64, Ruby 2.2.2 x64, using Pageant for authentication. If anyone still sees this, could you please post a minimal program to trigger this issue?

@ccoenen

This comment has been minimized.

Show comment
Hide comment
@ccoenen

ccoenen Jul 13, 2015

I use the following tiny script and the bug will turn up every other time. (Meaning it works sometimes).

The expected output is:

> C:\Tools\Ruby22-x64\bin\bundle exec C:\Tools\Ruby22-x64\bin\ruby netssh_poc.rb
ruby: 2.2.2
net-ssh: 2.10.0.beta2
--whatever your hostname is--
--whatever the id command returns--

Gemfile

source 'https://rubygems.org'
gem 'net-ssh', git: 'git@github.com:net-ssh/net-ssh.git', ref: 'bab0318'

netssh_poc.rb

SSH_HOST = 'example.com'
SSH_USER = 'root'

require 'rbconfig'
puts "ruby: #{RUBY_VERSION} / #{RbConfig::CONFIG['arch']}"

# intentionally delayed so the above will always print.
require 'net/ssh'
puts "net-ssh: #{Gem.loaded_specs['net-ssh'].version}"

begin
  Net::SSH.start(SSH_HOST, SSH_USER) do |ssh|
    puts ssh.exec!('hostname')
    puts ssh.exec!('id')
  end
rescue RangeError => e
  puts "ERROR: #{e} <==========================================="
  exit 1
end

(edit: begin/rescue added to make the output more manageable, also outputs the ruby architecture, now)

ccoenen commented Jul 13, 2015

I use the following tiny script and the bug will turn up every other time. (Meaning it works sometimes).

The expected output is:

> C:\Tools\Ruby22-x64\bin\bundle exec C:\Tools\Ruby22-x64\bin\ruby netssh_poc.rb
ruby: 2.2.2
net-ssh: 2.10.0.beta2
--whatever your hostname is--
--whatever the id command returns--

Gemfile

source 'https://rubygems.org'
gem 'net-ssh', git: 'git@github.com:net-ssh/net-ssh.git', ref: 'bab0318'

netssh_poc.rb

SSH_HOST = 'example.com'
SSH_USER = 'root'

require 'rbconfig'
puts "ruby: #{RUBY_VERSION} / #{RbConfig::CONFIG['arch']}"

# intentionally delayed so the above will always print.
require 'net/ssh'
puts "net-ssh: #{Gem.loaded_specs['net-ssh'].version}"

begin
  Net::SSH.start(SSH_HOST, SSH_USER) do |ssh|
    puts ssh.exec!('hostname')
    puts ssh.exec!('id')
  end
rescue RangeError => e
  puts "ERROR: #{e} <==========================================="
  exit 1
end

(edit: begin/rescue added to make the output more manageable, also outputs the ruby architecture, now)

@ccoenen

This comment has been minimized.

Show comment
Hide comment
@ccoenen

ccoenen Jul 13, 2015

On 64bit, i've had 8 successes (sometimes in little streaks) and 15 errors.

On 32bit, 20 out of 20 worked just fine.

ccoenen commented Jul 13, 2015

On 64bit, i've had 8 successes (sometimes in little streaks) and 15 errors.

On 32bit, 20 out of 20 worked just fine.

@pleaseking

This comment has been minimized.

Show comment
Hide comment
@pleaseking

pleaseking Jul 14, 2015

I managed to reproduce it either, but only sometimes, and don't see much logic. Restarting Pageant usually helps. Seems like non-initialized variable or something. Will try to take a closer look.

pleaseking commented Jul 14, 2015

I managed to reproduce it either, but only sometimes, and don't see much logic. Restarting Pageant usually helps. Seems like non-initialized variable or something. Will try to take a closer look.

@shirosaki

This comment has been minimized.

Show comment
Hide comment
@shirosaki

shirosaki Mar 30, 2016

This patch may solve the issue.
preturn_length.ptr.to_i is 8 bytes since pointer size is 8 bytes on 64bit OS.
The length should be long (4 bytes).

diff --git a/lib/net/ssh/authentication/pageant.rb b/lib/net/ssh/authentication/pageant.rb
index f0bf758..8a5bca2 100644
--- a/lib/net/ssh/authentication/pageant.rb
+++ b/lib/net/ssh/authentication/pageant.rb
@@ -254,7 +254,7 @@ module Net; module SSH; module Authentication
         Win.GetTokenInformation(token_handle,
                                 token_information_class,
                                 Win::NULL, 0, preturn_length)
-        ptoken_information = malloc_ptr(preturn_length.ptr.to_i)
+        ptoken_information = malloc_ptr(preturn_length.to_s(Win::SIZEOF_DWORD).unpack('L')[0])

         # This call is going to write the requested information to
         # the memory location referenced by token_information.

shirosaki commented Mar 30, 2016

This patch may solve the issue.
preturn_length.ptr.to_i is 8 bytes since pointer size is 8 bytes on 64bit OS.
The length should be long (4 bytes).

diff --git a/lib/net/ssh/authentication/pageant.rb b/lib/net/ssh/authentication/pageant.rb
index f0bf758..8a5bca2 100644
--- a/lib/net/ssh/authentication/pageant.rb
+++ b/lib/net/ssh/authentication/pageant.rb
@@ -254,7 +254,7 @@ module Net; module SSH; module Authentication
         Win.GetTokenInformation(token_handle,
                                 token_information_class,
                                 Win::NULL, 0, preturn_length)
-        ptoken_information = malloc_ptr(preturn_length.ptr.to_i)
+        ptoken_information = malloc_ptr(preturn_length.to_s(Win::SIZEOF_DWORD).unpack('L')[0])

         # This call is going to write the requested information to
         # the memory location referenced by token_information.

elconas added a commit to elconas/net-ssh that referenced this issue Jun 10, 2016

@elconas elconas referenced this issue Jun 20, 2016

Merged

Fix issue #235 #385

@mfazekas

This comment has been minimized.

Show comment
Hide comment
@mfazekas

mfazekas Jun 20, 2016

Collaborator

Can anyone confirm that #385 is a good fix for the issue?
If you have bundler then

gem 'net-ssh', :github => 'elconas/net-ssh', :branch => 'fix_issue_235-rebase2'

should get that patched version. It would be great to hear it's fixed on 32 bit and 64 bit windows too.

Collaborator

mfazekas commented Jun 20, 2016

Can anyone confirm that #385 is a good fix for the issue?
If you have bundler then

gem 'net-ssh', :github => 'elconas/net-ssh', :branch => 'fix_issue_235-rebase2'

should get that patched version. It would be great to hear it's fixed on 32 bit and 64 bit windows too.

@ccoenen

This comment has been minimized.

Show comment
Hide comment
@ccoenen

ccoenen commented Jun 20, 2016

@johnnyshields

This comment has been minimized.

Show comment
Hide comment
@johnnyshields

johnnyshields Aug 1, 2016

@mfazekas this seems to be a critical issue on Windows 10. since 4.0.0-beta1 is also having issues on windows to would it be possible to backport the fix in #385 and release as v3.2.1?

johnnyshields commented Aug 1, 2016

@mfazekas this seems to be a critical issue on Windows 10. since 4.0.0-beta1 is also having issues on windows to would it be possible to backport the fix in #385 and release as v3.2.1?

mfazekas added a commit to mfazekas/net-ssh that referenced this issue Aug 10, 2016

@vtanathip

This comment has been minimized.

Show comment
Hide comment
@vtanathip

vtanathip Aug 12, 2016

Hi All, I still have this error (bignum too big to convert into 'long') on

net-ssh: 3.2.0
gem: 2.4.5.1
ruby: 2.2.4p230

I try to connect my AWS cloud via ssh

Has anyone an Idea?

Thanks in advance

vtanathip commented Aug 12, 2016

Hi All, I still have this error (bignum too big to convert into 'long') on

net-ssh: 3.2.0
gem: 2.4.5.1
ruby: 2.2.4p230

I try to connect my AWS cloud via ssh

Has anyone an Idea?

Thanks in advance

@mfazekas

This comment has been minimized.

Show comment
Hide comment
@mfazekas

mfazekas Aug 12, 2016

Collaborator

Can you please try 3.2.1.beta1 or 4.0.0.beta2 only those has the fix intergrated.

Collaborator

mfazekas commented Aug 12, 2016

Can you please try 3.2.1.beta1 or 4.0.0.beta2 only those has the fix intergrated.

@vtanathip

This comment has been minimized.

Show comment
Hide comment
@vtanathip

vtanathip Aug 12, 2016

Hi @mfazekas , the problem is resolved!!!!.

Thanks for the advice. It will help many people during this time 👍

vtanathip commented Aug 12, 2016

Hi @mfazekas , the problem is resolved!!!!.

Thanks for the advice. It will help many people during this time 👍

@johnnyshields

This comment has been minimized.

Show comment
Hide comment
@johnnyshields

johnnyshields Aug 12, 2016

@mfazekas appreciated if you can release 3.2.1

johnnyshields commented Aug 12, 2016

@mfazekas appreciated if you can release 3.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment