[ 
https://issues.apache.org/jira/browse/THRIFT-610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12896589#action_12896589
 ] 

Bryan Duxbury commented on THRIFT-610:
--------------------------------------

Ah, yes, it looks like you were passing a "size" to the constructor of the 
transport, when what it actually takes is an initial buffer value. This would 
certainly cause the native code extensions to segfault when it tried to call 
pack. Incidentally, calling length on the result of inspect_buffer will 
overestimate the size of the actual payload by something like 3x.

Rajesh, I'll commit your patch for fixing the inspect_buffer method.

> binary_protocol.rb segfaults [line 86]
> --------------------------------------
>
>                 Key: THRIFT-610
>                 URL: https://issues.apache.org/jira/browse/THRIFT-610
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>    Affects Versions: 0.2
>         Environment: ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] - 
> svn checkout
> ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10.0.0] - git HEAD
>            Reporter: Andrew Kuhnhausen
>             Fix For: 0.5
>
>         Attachments: doot.pl, membuf-ruby19-fix.patch, thrift-segfaul.rb
>
>
> output from irb 1.8
> /usr/local/lib/site_ruby/1.8/thrift/protocol/binary_protocol.rb:86: [BUG] 
> Segmentation fault
> ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
> output from irb 1.9
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/protocol/binary_protocol.rb:86:
>  [BUG] Segmentation fault
> ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10.0.0]
> -- control frame ----------
> c:0028 p:---- s:0114 b:0114 l:000113 d:000113 CFUNC  :write
> c:0027 p:0029 s:0110 b:0110 l:000109 d:000109 METHOD 
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/protocol/binary_protocol.rb:86
> c:0026 p:0037 s:0106 b:0106 l:000105 d:000105 METHOD 
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/protocol/binary_protocol.rb:38
> c:0025 p:0029 s:0100 b:0100 l:000099 d:000099 METHOD 
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/client.rb:29
> c:0024 p:0050 s:0092 b:0092 l:000091 d:000091 METHOD 
> /Users/trane/Workspace/Ruby/stackable/thrift/gen-rb/container.rb:21
> c:0023 p:0045 s:0082 b:0082 l:000e28 d:001858 EVAL   (irb):11
> c:0022 p:---- s:0080 b:0080 l:000079 d:000079 FINISH
> c:0021 p:---- s:0078 b:0078 l:000077 d:000077 CFUNC  :eval
> c:0020 p:0027 s:0071 b:0071 l:000070 d:000070 METHOD 
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/workspace.rb:80
> c:0019 p:0031 s:0064 b:0063 l:000062 d:000062 METHOD 
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/context.rb:218
> c:0018 p:0030 s:0058 b:0058 l:001018 d:000057 BLOCK  
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:149
> c:0017 p:0037 s:0050 b:0050 l:000049 d:000049 METHOD 
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:263
> c:0016 p:0011 s:0045 b:0045 l:001018 d:000044 BLOCK  
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:146
> c:0015 p:0132 s:0041 b:0041 l:000024 d:000040 BLOCK  
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:244
> c:0014 p:---- s:0038 b:0038 l:000037 d:000037 FINISH
> c:0013 p:---- s:0036 b:0036 l:000035 d:000035 CFUNC  :loop
> c:0012 p:0009 s:0033 b:0033 l:000024 d:000032 BLOCK  
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:230
> c:0011 p:---- s:0031 b:0031 l:000030 d:000030 FINISH
> c:0010 p:---- s:0029 b:0029 l:000028 d:000028 CFUNC  :catch
> c:0009 p:0023 s:0025 b:0025 l:000024 d:000024 METHOD 
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:229
> c:0008 p:0042 s:0022 b:0022 l:001018 d:001018 METHOD 
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:145
> c:0007 p:0011 s:0019 b:0019 l:000f68 d:000018 BLOCK  
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:69
> c:0006 p:---- s:0017 b:0017 l:000016 d:000016 FINISH
> c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC  :catch
> c:0004 p:0172 s:0011 b:0011 l:000f68 d:000f68 METHOD 
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:68
> c:0003 p:0039 s:0006 b:0006 l:001988 d:001a28 EVAL   
> /usr/local/ruby1.9/bin/irb:12
> c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
> c:0001 p:0000 s:0002 b:0002 l:001988 d:001988 TOP   
> ---------------------------
> -- Ruby level backtrace information-----------------------------------------
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/protocol/binary_protocol.rb:86:in
>  `write'
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/protocol/binary_protocol.rb:86:in
>  `write_i16'
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/protocol/binary_protocol.rb:38:in
>  `write_message_begin'
> /usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/thrift-0.0.810255.1/lib/thrift/client.rb:29:in
>  `send_message'
> /Users/trane/Workspace/Ruby/stackable/thrift/gen-rb/container.rb:21:in 
> `send_create'
> (irb):11:in `irb_binding'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/workspace.rb:80:in `eval'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/workspace.rb:80:in `evaluate'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/context.rb:218:in `evaluate'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:149:in `block (2 levels) in 
> eval_input'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:263:in `signal_status'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:146:in `block in eval_input'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:244:in `block (2 levels) in 
> each_top_level_statement'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in `loop'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in `block in 
> each_top_level_statement'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `catch'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in 
> `each_top_level_statement'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:145:in `eval_input'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:69:in `block in start'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:68:in `catch'
> /usr/local/ruby1.9/lib/ruby/1.9.1/irb.rb:68:in `start'
> /usr/local/ruby1.9/bin/irb:12:in `<main>'
> -- C level backtrace information -------------------------------------------
> Line 21 of 'container.rb' (generated by thrift) is the method, send_create
>     def send_create(customerId, id, uuid, address, name, os, stack)
>       send_message('create', Create_args, :customerId => customerId, :id => 
> id, :uuid => uuid, :address => address, :name => name, :os => os, :stack => 
> stack)
>     end
> This is how the method 'send_create' is being called with irb1.9 output 
> (basically the same as irb1.8 output just with great back tracing):
> buffer = Thrift::MemoryBufferTransport.new(1024)
>      ### => #<Thrift::MemoryBufferTransport:0x0000010120d978 @buf=1024, 
> @index=0>
> protocol = Thrift::BinaryProtocol.new(buffer)
>     ###<Thrift::BinaryProtocol:0x000001011f73d0 
> @trans=#<Thrift::MemoryBufferTransport:0x0000010120d978 @buf=1024, @index=0>, 
> @strict_read=true, @strict_write=true>
> irb(main):009:0> client = Container::Client.new(protocol)
>     ###<Container::Client:0x000001011e8608 
> @iprot=#<Thrift::BinaryProtocol:0x000001011f73d0 
> @trans=#<Thrift::MemoryBufferTransport:0x0000010120d978 @buf=1024, @index=0>, 
> @strict_read=true, @strict_write=true>, 
> @oprot=#<Thrift::BinaryProtocol:0x000001011f73d0 
> @trans=#<Thrift::MemoryBufferTransport:0x0000010120d978 @buf=1024, @index=0>, 
> @strict_read=true, @strict_write=true>, @seqid=0>
> ### send_create(customerId, id, uuid, address, name, os, stack)
> client.send_create(
>   '0000',
>   '0',
>   '00xxx0x0-x0x0-00xx-xx00-x000x0x0xx00',
>   'www.whateveraddy.com',
>   'thrift_container',
>   '0',
>   '1'
> )
> then the output from the top comes out with the segfault.
> the error line refers to this in binary_protocol.rb
>     def write_i16(i16)
>       trans.write([i16].pack('n'))
>     end
> if that is removed, it fails on:
>     def write_i32(i32)
>       raise RangeError if i32 < -2**31 || i32 >= 2**31
>       trans.write([i32].pack('N'))
>     end

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to