You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Nevo Hed <nh...@aereo.com> on 2012/06/19 06:38:57 UTC

Deserialization failure with ruby

This is tested with thrift 0.7.0, and as it is pretty sensitive (removing
or changing the type of any of these definitions seems to make the problem
go away)
The failures are typically those of validation errors as you see below, but
other have been seen as well.

Has anyone seen anything like this?

Thanks
   -Nevo

--8<------------test.thrift-----------------------------------------------
enum En1 {
  EN1_0 = 1
}

struct MapEl {
  1: required En1 x1 = En1.EN1_0,
  2: required i32 x2 = 2,
  7: optional i32 x3 = 3,
  8: optional i32 x4 = 4,
}

struct topStruct {
  1: required i32            y1 = 1,
  2: required i16            y2 = 2,
  3: required i32            y3 = 3,
  4: optional map<i32,MapEl> y4 = {},
}

--8<------------test.rb----------------------------------------------------

#!/usr/bin/ruby
require 'thrift'
require 'gen-rb/test_types'

begin
  v=TopStruct.new

  for i in 1..124 do
    v.y4[i]=MapEl.new()
  end

  ruby_binary_protocol =
Thrift::BinaryProtocol.new(Thrift::MemoryBufferTransport.new)

  v.write(ruby_binary_protocol)
  TopStruct.new.read(ruby_binary_protocol)
  # drop read data on the floor

rescue Exception => tx
  print "Caught #{tx.class} exception: #{tx.message}\n"
  print "Trace:\n  ", tx.backtrace.join("\n  "), "\n"
end
nil

--8<----------------------------------------------------------------------

$ /usr/bin/thrift --gen rb test.thrift && ruby test.rb
Caught Thrift::ProtocolException exception: Invalid value of field x1!
Trace:
  ./gen-rb/test_types.rb:34:in `validate'
  test.rb:15:in `read'
  test.rb:15

Re: Deserialization failure with ruby

Posted by Nevo Hed <nh...@aereo.com>.
This looks to be an issue only with thrift_native

On Tue, Jun 19, 2012 at 12:38 AM, Nevo Hed <nh...@aereo.com> wrote:

>
> This is tested with thrift 0.7.0, and as it is pretty sensitive (removing
> or changing the type of any of these definitions seems to make the problem
> go away)
> The failures are typically those of validation errors as you see below,
> but other have been seen as well.
>
> Has anyone seen anything like this?
>
> Thanks
>    -Nevo
>
> --8<------------test.thrift-----------------------------------------------
> enum En1 {
>   EN1_0 = 1
> }
>
> struct MapEl {
>   1: required En1 x1 = En1.EN1_0,
>   2: required i32 x2 = 2,
>   7: optional i32 x3 = 3,
>   8: optional i32 x4 = 4,
> }
>
> struct topStruct {
>   1: required i32            y1 = 1,
>   2: required i16            y2 = 2,
>   3: required i32            y3 = 3,
>   4: optional map<i32,MapEl> y4 = {},
> }
>
> --8<------------test.rb----------------------------------------------------
>
> #!/usr/bin/ruby
> require 'thrift'
> require 'gen-rb/test_types'
>
> begin
>   v=TopStruct.new
>
>   for i in 1..124 do
>     v.y4[i]=MapEl.new()
>   end
>
>   ruby_binary_protocol =
> Thrift::BinaryProtocol.new(Thrift::MemoryBufferTransport.new)
>
>   v.write(ruby_binary_protocol)
>   TopStruct.new.read(ruby_binary_protocol)
>   # drop read data on the floor
>
> rescue Exception => tx
>   print "Caught #{tx.class} exception: #{tx.message}\n"
>   print "Trace:\n  ", tx.backtrace.join("\n  "), "\n"
> end
> nil
>
> --8<----------------------------------------------------------------------
>
> $ /usr/bin/thrift --gen rb test.thrift && ruby test.rb
> Caught Thrift::ProtocolException exception: Invalid value of field x1!
> Trace:
>   ./gen-rb/test_types.rb:34:in `validate'
>   test.rb:15:in `read'
>   test.rb:15
>
>