l3wi / mam.client.js

Masked Authentication Messaging wrapper for Javascript (Browser and Node)
GNU General Public License v3.0
15 stars 51 forks source link

Parsing at invalid root #12

Open bertschneider opened 6 years ago

bertschneider commented 6 years ago

When trying to use none MAM addresses as root the library sometimes throws an error Invalid addresses input or something like that. That is ok and the expected behavior. But sometimes a "thread panic" is produced and I guess that should not happen.

Here is an example with such an address:

const IOTA = require('iota.lib.js');
const Mam = require('mam.client.js/lib/mam.node');

const iota = new IOTA({ provider: 'https://field.carriota.com:443' });
console.log('Connected to:', iota.provider);

Mam.init(iota);

const fetchMamAtRoot = async (root) => {
    console.log('Fetching MAM at root:', root);
    try {
        return await Mam.fetch(root);
    } catch (e) {
        console.log(e);
    }
};
fetchMamAtRoot('YQHVRO9JODMBLKO9AZJLZDAWGNODOCF9UFUTXXO9JSLYPKOKVZHADMIILBRP9RTETQ9QRIFZACTBBIUPD');

Running the code I get the following output:

Connected to: https://field.carriota.com:443
Fetching MAM at root: YQHVRO9JODMBLKO9AZJLZDAWGNODOCF9UFUTXXO9JSLYPKOKVZHADMIILBRP9RTETQ9QRIFZACTBBIUPD
thread '<unnamed>' panicked at 'index 3 out of range for slice of length 0', /checkout/src/libcore/slice/mod.rs:746:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failed to parse:  5275984

I tried it on macOS 10.13.13, node v9.6.1.