anthonykirby / lora-packet

LoRa radio packet decoder
MIT License
258 stars 83 forks source link

.toString() function giving "Attempt to access memory outside buffer bounds" on Join Accept messages #114

Closed aqllmcdavid closed 10 months ago

aqllmcdavid commented 10 months ago

I wrote a script that logs out packets as they are received from the sensors. Data messages work without issue, however when it tries to read in a Join Accept it will throw an error when stringify is attempted.

var loraPacket  = require('lora-packet');

let payload;

payload = "MIAAAA==";
// payload = "QPF9vkkAAgABlUN4disR/w0="; // base64 equivalent to 40F17DBE4900020001954378762B11FF0D used on the npm example

let bytes = Buffer.from(payload, "base64");
let packet = loraPacket.fromWire(bytes);

console.log(packet.toString());

If you uncomment the second payload, .toString() will work without issue.

This occurs on every join accept received, currently I am simply ignoring the output of these message types but it would be extremely helpful if this data could be logged in this format.

anthonykirby commented 10 months ago

thanks; I'll investigate

anthonykirby commented 10 months ago

The payload MIAAAA== is 30800000 in hex, i.e. 4 bytes

This can't possibly be a valid "Join Accept", which should be 17 or 33 bytes long

lora-packet should throw an error in fromWire(); I'll fix that.