markabrahams / node-asn1-ber

Generate and parse ASN.1 BER objects
7 stars 8 forks source link

Negative numbers are read when unsigned integers should be used in some places #1

Closed stephenwvickers closed 7 years ago

stephenwvickers commented 7 years ago

See: https://github.com/mcavage/node-asn1/issues/24

stephenwvickers commented 7 years ago

Original requester: @rjrivero

stephenwvickers commented 7 years ago

This will require more investigation. If it is deemed to be an issue I will address in 1.0.0 by the end of the week, otherwise I may need to consult with the original requester.

stephenwvickers commented 7 years ago

Original problem description:

I think there is a problem in the readOID function when a value in the OID is higher than 2^31. It is returning negative numbers. For example:

var ber = require("asn1").Ber;

// Buffer contains OID 1.3.6.1.4.1.14988.1.1.5.1.1.19.2887117176 var data = new Buffer([6,18,43,6,1,4,1,245,12,1,1,5,1,1,19,138,224,215,210,120]); var reader = new ber.Reader (data) console.log(reader.readOID()); // prints "1.3.6.1.4.1.14988.1.1.5.1.1.19.-1407850120" A possible fix would be casting each value to unsigned integer before storing. I.e replacing values.push(value) with values.push(value >>> 0)

stephenwvickers commented 7 years ago

User @varadi commented:

I agree with @rjrivero. I ran into the same problem with 32bit OIDs and values.push(value >>> 0) should solve it? Please also

add a release note that this implantation limits OIDs to 32bit (readOID and writeOID) log an error if an OID exceeds 32 bit, i.e. if the sequence has more than 5 bytes, or has 5 bytes but the first byte has bits 1, 2 or 3 set (bit 0 is 1).