node-jpickle icon indicating copy to clipboard operation
node-jpickle copied to clipboard

Unhandled opcode '128'

Open foxt opened this issue 3 years ago • 4 comments

Hi, I'm trying to decode Pickle'd objects in JS.

Running the following code works

pickle.loads(open("test2.bin","rb").read(),encoding='latin1')

However this does not

var f = Pickle.loads(AUint8Array)

I get ` Unhandled opcode '128' (the file starts with 80 02 7D 71 01 28 58 17 00 00 00)

Any help would be appreciated.

foxt avatar Mar 20 '21 17:03 foxt

Fixed by replacing the switch (opcode) with switch (String.fromCharCode(opcode))

This could be a weird WebJS/NodeJS incompatibility.

[...]
        var opindex = i
          , opcode = pickle[i++];
        //console.log('opcode ' + opindex + ' ' + opcode);
        switch (String.fromCharCode(opcode)) {
            // protocol 2
            case PROTO:
[...]

foxt avatar Mar 20 '21 19:03 foxt

fix in #13

foxt avatar Dec 21 '21 03:12 foxt

@foxt you should reopen this as its not merged yet!

boltex avatar Nov 17 '23 23:11 boltex

@foxt oops, I thought you were on to something but I did this in my code and I understood why the existing codebase is ok. :

val = pickle.loads(String.fromCharCode(...inflated));

(inflated is the content I had retrived from some source, which was not exactly like pickle.loads required)

Your well intentioned pull request is not relevant anymore. (Sorry i distracted you with this earlier today) I also thought it was, but after reading about how to convert binary data to the proper format that pickle.loads requires made me realize It was ok all along and i was the one who misunderstood the codebase of jpickle.

boltex avatar Nov 18 '23 03:11 boltex