Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1183

Pure-ruby CompactProtocol raises ArgumentError when deserializing under Ruby 1.9

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.6.1
    • 0.7
    • Ruby - Library
    • None
    • OS X 10.6 i686 / Ruby 1.9.2

    • Patch Available

    Description

      While testing my fix for THRIFT-1182 with various combinations of native/non-native ruby and binary/compact protocols, I stumbled upon a bug in the pure-ruby implementation of CompactProtocol.

      In lib/thrift/protocol/compact_protocol.rb line 306:
      ...
      val = dat[0]
      if (val > 0x7f)
      ...
      Here, dat is a string, so dat[0] returns a Fixnum in Ruby 1.8.7 but a string of size 1 in Ruby 1.9.2. The conditional compares dat[0] with 0x7f, which raises the following error in 1.9.2:

      /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/protocol/compact_protocol.rb:307:in `>': comparison of String with 127 failed (ArgumentError)
      from /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/protocol/compact_protocol.rb:307:in `read_byte'
      from /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/protocol/compact_protocol.rb:243:in `read_field_begin'
      from /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/struct.rb:86:in `block in read'
      from /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/struct.rb:85:in `loop'
      from /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/struct.rb:85:in `read'
      from /Users/ilyam/.rvm/gems/ruby-1.9.2-p180/gems/thrift-0.6.0/lib/thrift/serializer/deserializer.rb:29:in `deserialize'

      The solution is a one-line fix, patch will be attached shortly.

      Attachments

        1. patch-THRIFT-1183.txt
          0.5 kB
          Ilya Maykov

        Activity

          People

            ilyam Ilya Maykov
            ilyam Ilya Maykov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: