shorty icon indicating copy to clipboard operation
shorty copied to clipboard

PDU Parser fails when parsing type "string"

Open MichaelKling opened this issue 7 years ago • 0 comments

Parsing an incomming (deliver_sm) sms, the library crashed with the following error:

RangeError: out of range index
    at RangeError (native)
    at Object.exports.parse (.\node_modules\shorty\lib\pdu-parser.js:163:20)
    at Object.exports.fromBuffer (.\node_modules\shorty\lib\data-handler.js:76:22)
...

It seems that even though in the comment of the function it is explicitly stated

the length of the string will be specified by the value parsed in the field named by length_field

, the copy call in line 163 is still using field.length, instead of the determined length in line 161. But field.length is undefined in that case.

Changing line 163 from buffer.copy(temp, 0, offset, offset + field.length); to buffer.copy(temp, 0, offset, offset + length); seems to fix the issue.

MichaelKling avatar Nov 02 '17 23:11 MichaelKling