Skip to content

Fix encoding of int64/bool keys of maps in encoder#1653

Closed
reebalazs wants to merge 3 commits into
protobufjs:masterfrom
reebalazs:fix-int64-keyed-maps-encode-generation
Closed

Fix encoding of int64/bool keys of maps in encoder#1653
reebalazs wants to merge 3 commits into
protobufjs:masterfrom
reebalazs:fix-int64-keyed-maps-encode-generation

Conversation

@reebalazs
Copy link
Copy Markdown

Fixes #1652 .

The int64 writer cannot handle the hash directly, because it interprets
it as a string representation of a Long number, instead of a hash.

This is obviously wrong, because the input at this point always contains the longbit hashes already. So the int64() writer fails inevitably.

I believe that the simplest solution is: Explicit conversion from hash to long is needed before writing.

Again (just like with the other PR I submitted) I believe that the tests are missing for the generated encode/decode functions. If there were such tests, it would be fairly straightforward to write a test case that exercises this problem, and proves that the fix, in fact, works.

The int64 writer cannot handle the hash directly, because it interprets
it as a string representation of a Long number, instead of a hash.
Explicit conversion from hash to long is needed before writing.
Exactly the same issue with bool key types as well. Extend the fix
to cover this case too.
@reebalazs reebalazs changed the title Fix encoding of int64 keys of maps in encoder Fix encoding of int64/bool keys of maps in encoder Sep 17, 2021
@reebalazs
Copy link
Copy Markdown
Author

Exactly same case with a bool key type. Fix extended to cover this case as well.

Comment thread src/encoder.js
The fix has to be extended to all int64 key types.
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

Successfully merging this pull request may close these issues.

map field with int64/bool type has broken key in generated encode function

3 participants