Skip to content
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

Varint decoding (in Ruby) fails with "invalid byte sequence in UTF-8" #6

Closed
ghost opened this issue Mar 11, 2013 · 1 comment
Closed

Comments

@ghost
Copy link

ghost commented Mar 11, 2013

Decoding a GTFS-realtime message fails for me with a ProtocolBuffers::DecodeError, "error parsing message". Debugging using "ruby -rdebug" (see below) reveals varint.decode is failing trying to read from the input stream using io.getc (varint.rb:30).

Looks to me the code here should be trying to read a byte and not a UTF-8 character, so the error makes sense. Should this line be "io.read(1).ord" instead? That change fixes the problem for me and the message is parsed successfully. (Seems both Ruby 1.8 and 1.9 have an IO.read method, and the method is provided by the LimitedIO class as well.)


/usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/varint.rb:30: ' (NilClass) from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:274:inparse'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:280:in parse' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/field.rb:601:indeserialize'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/decoder.rb:57:in decode' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:274:inparse'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:280:in parse' from ./test.rb:6:inblock in

'
from ./test.rb:5:in open' from ./test.rb:5:in'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/varint.rb:30: byte = io.getc.ord
(rdb:1) c
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/decoder.rb:88: invalid byte sequence in UTF-8' (ArgumentError) from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:280:inparse'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/field.rb:601:in deserialize' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/decoder.rb:57:indecode'
from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:274:in parse' from /usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/message.rb:280:inparse'
from ./test.rb:6:in block in <main>' from ./test.rb:5:inopen'
from ./test.rb:5:in `'
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-protocol-buffers-1.3.2/lib/protocol_buffers/runtime/decoder.rb:88: raise(DecodeError, "error parsing message")

@codekitchen
Copy link
Owner

Oh wow, I wonder how in the world that's slipped through for so long. I'm guessing we must typically get the strings ascii/binary encoded, so there are no multi-byte characters. Thanks for the report, I'll work on a fix soon if you don't.

codekitchen pushed a commit that referenced this issue Aug 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant