Contents

liuliu/swift-fickling

This is inspired by work from Trail of Bits on [Fickling](https://github.com/trailofbits/fickling). Many Stable Diffusion models are published in pickle format. Pickle format has been traditionally tied to a Python installation. This limitation exists also because pickle has the

Limitations

The current implementation would be wrong for some pickle files. The main cause is how Python and Swift treat dictionaries and arrays (lists) differently.

In Swift, dictionaries and arrays are value types. If you mutate a dictionary, it won't affects objects previously holding that dictionary. Pickle VM follows Harvard architecture. If you mutate a dictionary from the stack, but the same dictionary was also held by the lookup memory, they will diverge. Luckily, this doesn't happen for pickle files I care about because most pickle files only ever call SETITEMS once on a dictionary to build them.

It is possible to solve this issue by wrapping dictionaries and arrays into a class type, I need examples of such pickle file to start this work. It may also requires me to introduce similar things like PythonObject in PythonKit to wrap around some usages. We are not there yet.

Package Metadata

Repository: liuliu/swift-fickling

Default branch: main

README: README.md