Forum Archive

Too many iterations causing pythonista to crash (lastpass module/simple-pbkdf2)

userista

I am trying to get the lastpass-python module working on Pythonista but it keeps on crashing Pythonista. I traced the issue down to when it tries to create a binary digest on line 124 in fetcher.py, it seems to start executing that line and then crashes. I'm guessing Pythonista has an issue storing binary data, is that a possibility?

(Obviously I downloaded all the requirements - simple-pbkdf2 and mock.)

Edit: here's example code to execute in the console which will crash the app.

userista

Ok I figured out the exact point of crash. When simple-pbkdf2 is creating the binary digest it iterates using the given iteration parameter. See here. Now, lastpass's "API" returns an iteration count which must be used to create the digest. However, if the iteration is greater than ~4800 then simple-pbkdf2 crashes Pythonista while iterating (runs out of memory? - I'm on iPhone 5 7.0.x). I tested with an iteration count of <=4700 and it works fine. Is there any way that this can be fixed, Ole? Or is it a hardware limitation?
Thanks!

omz

It seems like simple-pbkdf2 is causing a stack overflow somewhere in functools. There isn't much I can do about this, but I can suggest a workaround for what you're trying to do.

I've modified fetcher.py to work with the pbkdf2 1.3 module instead of simple-pbkdf2. Here's my modified version: https://gist.github.com/omz/ba1ed16ab1b728dbde6d

Simply replace pbkdf2.py with the version from the pbkdf2 1.3 module and replace fetcher.py with the contents of my gist above (you may need to restart Pythonista in case the old modules are still cached).

I've been able to get it to work this way, hope it helps.

userista

Awesome! It works! Thanks so much! Now I have to work on parsing and importing it into the keychain.