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

js/binary/utils.js: Fix jspb.utils.joinUnsignedDecimalString to work with negative bitsLow and low but non-zero bitsHigh parameter. #8170

Merged
merged 1 commit into from Jan 8, 2021

Conversation

reltuk
Copy link
Contributor

@reltuk reltuk commented Dec 30, 2020

We noticed that our generated javascript message implementations decode certain number fields incorrectly for some values when the fields have jstype = JS_STRING. I tracked it down to readZigzagVarint64String(), which does not always decode a field correctly. In particular, it returns the wrong result when it calls into jspb.utils.joinUnsignedDecimalString with a bitsLow value that is negative and a bitsHigh value that is less than 0x1FFFFF. None of the existing test cases appear to cover that case.

This PR changes joinUnsignedDecimalString to call jspb.utils.joinUint64 on its fast path instead, which gets us the right result.

It's also possible to change the line to

return '' + (jspb.BinaryConstants.TWO_TO_32 * bitsHigh + (bitsLow >>> 0));

or similar instead.

This is my first contact with this code and it wasn't clear to me if the bug is actually in the caller of joinUnsignedDecimalString. If joinUnsignedDecimalString is expecting purely unsigned parameters then it's possible that this isn't the desired fix. But it would be great if we could get a fix landed :).

Thanks for the awesome project which we make great use of throughout our stack :).

…with negative bitsLow and low but non-zero bitsHigh parameter.
@google-cla
Copy link

google-cla bot commented Dec 30, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Dec 30, 2020
@reltuk
Copy link
Contributor Author

reltuk commented Dec 30, 2020

@googlebot I signed it!

Copy link
Contributor

@perezd perezd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for your contribution!

@perezd perezd merged commit 10599e6 into protocolbuffers:master Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants