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

Invalid int64 decoding of negative values #44

Open
gmartsenkov opened this issue Jan 1, 2022 · 3 comments
Open

Invalid int64 decoding of negative values #44

gmartsenkov opened this issue Jan 1, 2022 · 3 comments

Comments

@gmartsenkov
Copy link

Encoding negative i64 produces a wrong number, this might as well be the case for i32;

  it "V3 int64 encode decode" do
    msg = TestMessagesV3::Test3.new
    msg.f2=-15000_i64

    some_io = IO::Memory.new
    msg.to_protobuf some_io

    some_io.rewind

    msg2 = TestMessagesV3::Test3.from_protobuf some_io
    msg2.f2.should eq -15000_i64
  end

Fails with:

Failures:

  1) Protobuf::Message V3 int64 encode decode
     Failure/Error: msg2.f2.should eq -15000_i64

       Expected: -15000
            got: 9223372036854760808

     # spec/protobuf/decode_spec.cr:31
@jgaskins
Copy link
Collaborator

jgaskins commented Jan 2, 2022

@gmartsenkov Interesting, thanks for the report. There must be a bug in handling of the sign bit in either read_int64 or write_int64. I'll have a look.

@jgaskins
Copy link
Collaborator

jgaskins commented Jan 2, 2022

Confirmed that removing this conditional makes that spec pass, and that ensures we read and write them the same way, but doesn't validate that that way is correct. To confirm that, we'll want to test against known valid serializations of some negative integers.

Thanks again for this. I've somehow never run into this issue, which is pretty wild.

@gmartsenkov
Copy link
Author

No worries, I was pretty bamboozled at first :D I tested it manually and what you suggested seems to fix my specific issue too. Thanks for the quick response!

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

2 participants