You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Sinan Taifour (JIRA)" <ji...@apache.org> on 2009/08/27 11:56:59 UTC

[jira] Created: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Segmentation Fault when using BinaryProtocolAccelerated in Ruby
---------------------------------------------------------------

                 Key: THRIFT-569
                 URL: https://issues.apache.org/jira/browse/THRIFT-569
             Project: Thrift
          Issue Type: Bug
          Components: Library (Ruby)
         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
            Reporter: Sinan Taifour


When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).

Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.

Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).

Index: lib/rb/ext/binary_protocol_accelerated.c
===================================================================
--- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
+++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
@@ -76,6 +76,9 @@
 }
 
 static void write_string_direct(VALUE trans, VALUE str) {
+  if (TYPE(str) != T_STRING) {
+    rb_raise(rb_eStandardError, "Value should be a string");   
+  }
   write_i32_direct(trans, RSTRING_LEN(str));
   rb_funcall(trans, write_method_id, 1, str);
 }

Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:

test.thrift
===================================================================
service Test {
  i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
}

server.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

class TestHandler
  def c1(p1, p2, p3)
    p1 + p2
  end
end

handler = TestHandler.new()
processor = Test::Processor.new(handler)
transport = Thrift::ServerSocket.new(9090)
transportFactory = Thrift::BufferedTransportFactory.new()
protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)

server.serve()

client.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
srv       = Test::Client.new(protocol)
transport.open()

p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch


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


[jira] Updated: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Posted by "Sinan Taifour (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-569?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sinan Taifour updated THRIFT-569:
---------------------------------

    Description: 
When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).

Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.

Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).

{noformat}
Index: lib/rb/ext/binary_protocol_accelerated.c
===================================================================
--- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
+++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
@@ -76,6 +76,9 @@
 }
 
 static void write_string_direct(VALUE trans, VALUE str) {
+  if (TYPE(str) != T_STRING) {
+    rb_raise(rb_eStandardError, "Value should be a string");   
+  }
   write_i32_direct(trans, RSTRING_LEN(str));
   rb_funcall(trans, write_method_id, 1, str);
 }
{noformat}

Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:

{noformat}
test.thrift
===================================================================
service Test {
  i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
}

server.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

class TestHandler
  def c1(p1, p2, p3)
    p1 + p2
  end
end

handler = TestHandler.new()
processor = Test::Processor.new(handler)
transport = Thrift::ServerSocket.new(9090)
transportFactory = Thrift::BufferedTransportFactory.new()
protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)

server.serve()

client.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
srv       = Test::Client.new(protocol)
transport.open()

p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch
{noformat}

  was:
When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).

Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.

Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).

Index: lib/rb/ext/binary_protocol_accelerated.c
===================================================================
--- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
+++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
@@ -76,6 +76,9 @@
 }
 
 static void write_string_direct(VALUE trans, VALUE str) {
+  if (TYPE(str) != T_STRING) {
+    rb_raise(rb_eStandardError, "Value should be a string");   
+  }
   write_i32_direct(trans, RSTRING_LEN(str));
   rb_funcall(trans, write_method_id, 1, str);
 }

Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:

test.thrift
===================================================================
service Test {
  i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
}

server.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

class TestHandler
  def c1(p1, p2, p3)
    p1 + p2
  end
end

handler = TestHandler.new()
processor = Test::Processor.new(handler)
transport = Thrift::ServerSocket.new(9090)
transportFactory = Thrift::BufferedTransportFactory.new()
protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)

server.serve()

client.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
srv       = Test::Client.new(protocol)
transport.open()

p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch



Using {noformat}.

> Segmentation Fault when using BinaryProtocolAccelerated in Ruby
> ---------------------------------------------------------------
>
>                 Key: THRIFT-569
>                 URL: https://issues.apache.org/jira/browse/THRIFT-569
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
>            Reporter: Sinan Taifour
>
> When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).
> Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.
> Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).
> {noformat}
> Index: lib/rb/ext/binary_protocol_accelerated.c
> ===================================================================
> --- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
> +++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
> @@ -76,6 +76,9 @@
>  }
>  
>  static void write_string_direct(VALUE trans, VALUE str) {
> +  if (TYPE(str) != T_STRING) {
> +    rb_raise(rb_eStandardError, "Value should be a string");   
> +  }
>    write_i32_direct(trans, RSTRING_LEN(str));
>    rb_funcall(trans, write_method_id, 1, str);
>  }
> {noformat}
> Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:
> {noformat}
> test.thrift
> ===================================================================
> service Test {
>   i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
> }
> server.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> class TestHandler
>   def c1(p1, p2, p3)
>     p1 + p2
>   end
> end
> handler = TestHandler.new()
> processor = Test::Processor.new(handler)
> transport = Thrift::ServerSocket.new(9090)
> transportFactory = Thrift::BufferedTransportFactory.new()
> protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
> server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)
> server.serve()
> client.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
> protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
> srv       = Test::Client.new(protocol)
> transport.open()
> p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch
> {noformat}

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


[jira] Updated: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Posted by "Sinan Taifour (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-569?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sinan Taifour updated THRIFT-569:
---------------------------------

    Attachment: thrift-r807972-patch.diff

The patch.

> Segmentation Fault when using BinaryProtocolAccelerated in Ruby
> ---------------------------------------------------------------
>
>                 Key: THRIFT-569
>                 URL: https://issues.apache.org/jira/browse/THRIFT-569
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
>            Reporter: Sinan Taifour
>         Attachments: thrift-r807972-patch.diff
>
>
> When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).
> Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.
> Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).
> {noformat}
> Index: lib/rb/ext/binary_protocol_accelerated.c
> ===================================================================
> --- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
> +++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
> @@ -76,6 +76,9 @@
>  }
>  
>  static void write_string_direct(VALUE trans, VALUE str) {
> +  if (TYPE(str) != T_STRING) {
> +    rb_raise(rb_eStandardError, "Value should be a string");   
> +  }
>    write_i32_direct(trans, RSTRING_LEN(str));
>    rb_funcall(trans, write_method_id, 1, str);
>  }
> {noformat}
> Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:
> {noformat}
> test.thrift
> ===================================================================
> service Test {
>   i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
> }
> server.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> class TestHandler
>   def c1(p1, p2, p3)
>     p1 + p2
>   end
> end
> handler = TestHandler.new()
> processor = Test::Processor.new(handler)
> transport = Thrift::ServerSocket.new(9090)
> transportFactory = Thrift::BufferedTransportFactory.new()
> protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
> server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)
> server.serve()
> client.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
> protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
> srv       = Test::Client.new(protocol)
> transport.open()
> p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch
> {noformat}

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


[jira] Updated: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Posted by "Sinan Taifour (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-569?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sinan Taifour updated THRIFT-569:
---------------------------------

    Description: 
When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).

Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.

Attached is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).

Also, attached is a set of files that can be used to reproduce the segmentation fault mentioned.

  was:
When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).

Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.

Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).

{noformat}
Index: lib/rb/ext/binary_protocol_accelerated.c
===================================================================
--- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
+++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
@@ -76,6 +76,9 @@
 }
 
 static void write_string_direct(VALUE trans, VALUE str) {
+  if (TYPE(str) != T_STRING) {
+    rb_raise(rb_eStandardError, "Value should be a string");   
+  }
   write_i32_direct(trans, RSTRING_LEN(str));
   rb_funcall(trans, write_method_id, 1, str);
 }
{noformat}

Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:

{noformat}
test.thrift
===================================================================
service Test {
  i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
}

server.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

class TestHandler
  def c1(p1, p2, p3)
    p1 + p2
  end
end

handler = TestHandler.new()
processor = Test::Processor.new(handler)
transport = Thrift::ServerSocket.new(9090)
transportFactory = Thrift::BufferedTransportFactory.new()
protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)

server.serve()

client.rb
===================================================================
require 'rubygems'
require 'thrift'
require 'extlib'
CURDIR = File.dirname(__FILE__)
$: << CURDIR / "gen-rb"
Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }

transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
srv       = Test::Client.new(protocol)
transport.open()

p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch
{noformat}


Removed inline code, files are attached instead.

> Segmentation Fault when using BinaryProtocolAccelerated in Ruby
> ---------------------------------------------------------------
>
>                 Key: THRIFT-569
>                 URL: https://issues.apache.org/jira/browse/THRIFT-569
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
>            Reporter: Sinan Taifour
>         Attachments: client.rb, server.rb, test.thrift, thrift-r807972-patch.diff
>
>
> When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).
> Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.
> Attached is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).
> Also, attached is a set of files that can be used to reproduce the segmentation fault mentioned.

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


[jira] Commented: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-569?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748424#action_12748424 ] 

Bryan Duxbury commented on THRIFT-569:
--------------------------------------

Instead of pasting the patch in the description, can you attach the patch as a file? There's a checkbox on there that grants license to the ASF. Thanks!

> Segmentation Fault when using BinaryProtocolAccelerated in Ruby
> ---------------------------------------------------------------
>
>                 Key: THRIFT-569
>                 URL: https://issues.apache.org/jira/browse/THRIFT-569
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
>            Reporter: Sinan Taifour
>
> When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).
> Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.
> Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).
> {noformat}
> Index: lib/rb/ext/binary_protocol_accelerated.c
> ===================================================================
> --- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
> +++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
> @@ -76,6 +76,9 @@
>  }
>  
>  static void write_string_direct(VALUE trans, VALUE str) {
> +  if (TYPE(str) != T_STRING) {
> +    rb_raise(rb_eStandardError, "Value should be a string");   
> +  }
>    write_i32_direct(trans, RSTRING_LEN(str));
>    rb_funcall(trans, write_method_id, 1, str);
>  }
> {noformat}
> Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:
> {noformat}
> test.thrift
> ===================================================================
> service Test {
>   i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
> }
> server.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> class TestHandler
>   def c1(p1, p2, p3)
>     p1 + p2
>   end
> end
> handler = TestHandler.new()
> processor = Test::Processor.new(handler)
> transport = Thrift::ServerSocket.new(9090)
> transportFactory = Thrift::BufferedTransportFactory.new()
> protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
> server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)
> server.serve()
> client.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
> protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
> srv       = Test::Client.new(protocol)
> transport.open()
> p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch
> {noformat}

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


[jira] Updated: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Posted by "Sinan Taifour (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-569?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sinan Taifour updated THRIFT-569:
---------------------------------

    Attachment: client.rb
                server.rb
                test.thrift

These files can be used to recreate the segmentation fault.

> Segmentation Fault when using BinaryProtocolAccelerated in Ruby
> ---------------------------------------------------------------
>
>                 Key: THRIFT-569
>                 URL: https://issues.apache.org/jira/browse/THRIFT-569
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
>            Reporter: Sinan Taifour
>         Attachments: client.rb, server.rb, test.thrift, thrift-r807972-patch.diff
>
>
> When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).
> Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.
> Below is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).
> {noformat}
> Index: lib/rb/ext/binary_protocol_accelerated.c
> ===================================================================
> --- lib/rb/ext/binary_protocol_accelerated.c    (revision 807972)
> +++ lib/rb/ext/binary_protocol_accelerated.c    (working copy)
> @@ -76,6 +76,9 @@
>  }
>  
>  static void write_string_direct(VALUE trans, VALUE str) {
> +  if (TYPE(str) != T_STRING) {
> +    rb_raise(rb_eStandardError, "Value should be a string");   
> +  }
>    write_i32_direct(trans, RSTRING_LEN(str));
>    rb_funcall(trans, write_method_id, 1, str);
>  }
> {noformat}
> Also, below you can find a set of files that can be used to reproduce the segmentation fault mentioned:
> {noformat}
> test.thrift
> ===================================================================
> service Test {
>   i32 c1(1: i32 p1, 2: i32 p2, 3: map<string,string> p3)
> }
> server.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> class TestHandler
>   def c1(p1, p2, p3)
>     p1 + p2
>   end
> end
> handler = TestHandler.new()
> processor = Test::Processor.new(handler)
> transport = Thrift::ServerSocket.new(9090)
> transportFactory = Thrift::BufferedTransportFactory.new()
> protocolFactory = Thrift::BinaryProtocolAcceleratedFactory.new
> server = Thrift::ThreadPoolServer.new(processor, transport, transportFactory, protocolFactory)
> server.serve()
> client.rb
> ===================================================================
> require 'rubygems'
> require 'thrift'
> require 'extlib'
> CURDIR = File.dirname(__FILE__)
> $: << CURDIR / "gen-rb"
> Dir[CURDIR / "gen-rb" / "**" / "*"].each { |f| require f unless File.directory?(f) }
> transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost', 9090))
> protocol  = Thrift::BinaryProtocolAccelerated.new(transport)
> srv       = Test::Client.new(protocol)
> transport.open()
> p srv.c1(1,1,{'asfd' => true}) # Causes segmentaion fault without the patch, raises an error with the patch
> {noformat}

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


[jira] Resolved: (THRIFT-569) Segmentation Fault when using BinaryProtocolAccelerated in Ruby

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-569?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury resolved THRIFT-569.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 0.2
         Assignee: Sinan Taifour

I just committed this patch. Thanks Sinan!

> Segmentation Fault when using BinaryProtocolAccelerated in Ruby
> ---------------------------------------------------------------
>
>                 Key: THRIFT-569
>                 URL: https://issues.apache.org/jira/browse/THRIFT-569
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (Ruby)
>         Environment: Linux 2.6.31-4-generic, Ruby 1.8.7, Thrift r807972
>            Reporter: Sinan Taifour
>            Assignee: Sinan Taifour
>             Fix For: 0.2
>
>         Attachments: client.rb, server.rb, test.thrift, thrift-r807972-patch.diff
>
>
> When using the BinaryProtocolAccelerated in Ruby, and expecting a map<string,string> and getting something else, a segmentation fault occurs. I was able to trace the segmentation fault back to binary_protocol_accelerated.c, in r807972, the problem is in RSTRING_LEN(str) inside write_string_direct(...).
> Notice that, in the Python implementation, or when using BinaryProtocol as opposed to BinaryProtocolAccelerated, an exception is raised when a value has a type other than string in a map<string, string>.
> Attached is a patch that solved the problem for me, please advise on whether or not this would be the right way to solve it (it appears to work properly in different cases).
> Also, attached is a set of files that can be used to reproduce the segmentation fault mentioned.

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