Skip to content

Negative int32 values are not decoded properly. #62

@duaneellissd

Description

@duaneellissd

Module: encodings.js - function int32 - is wrong.
It does not properly decode negative numbers.

For example "-15" encodes as 10 bytes
0xf1 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x01

The return value from "varint" is a giant number
As each byte is decode, the result value becomes:
BYTE is: 241 res: 0
BYTE is: 255 res: 113
BYTE is: 255 res: 16369
BYTE is: 255 res: 2097137
BYTE is: 255 res: 268435441
BYTE is: 255 res: 34359738353
BYTE is: 255 res: 4398046511089
BYTE is: 255 res: 562949953421297
BYTE is: 255 res: 72057594037927920
BYTE is: 1 res: 9223372036854776000
Result: 18446744073709552000
int32, value = 18446744073709552000 (Which is the unsigned value)

Above is the proper return value from "varint" the problem is in the encoding.js file

The 'pseudo-negative' test is correct, ie: if the value is > 2147483647 [then the value is negative]

however , the code that should adjust for a negative number is just wrong.

This is with "node.exe" windows, v4.2.6, on Win7 64bit, I have not tried other platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions