[Python-ideas] Python Bytecode Verifier

Kornél Pál kornelpal at gmail.com
Wed Mar 4 10:21:33 CET 2009


I've created a Python Bytecode Verifier in Python. I'm not a Python
guru so I borrowed coding patterns from C/C++. I also created this
with C portability in mind. The only reason I used Python was to
experiment with Python and was easier to morph code during

If this program were ported to C it would only need 8 bytes per opcode
(some additional storage to track blocks) and a single pass. I haven't
found backward jumps to previously unused code in any compiled Python
code but it can easily be supported. In that case some more partial
passes are required.

I also was able to successfully verify all Python files in the
Python-2.5.2 source package.

The verification algorythm should be quite complete but I may have
missed some limitations of the interpreter that could be checked by
the verifier as well.

The ability to create this verfier proved that although Python
bytecode is designed for a dynamically typed interpreter, is still
easily verifiable. I am willing port this code C but only in the case
if there is any chance to be included in Python.

I believe that Python in general would benefit having the ability to
safely load .pyc files and create code objects on the fly.

Both Java and .NET have the ability to safely load compiled byte code.
.NET Framework, just like Python also has the ability to create and
execute new code at run-time.

You may feel that enabling closed source applications and/or creating
a multi-language runtime would hurt Python but both of these have
contributed to the success of Java (both the language and the

-------------- next part --------------
A non-text attachment was scrubbed...
Name: verifier.py
Type: application/octet-stream
Size: 22908 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090304/7cef48d9/attachment.obj>

More information about the Python-ideas mailing list