Skip to content

Fix AttributeError when encoding an INST opcode - #321

Open
coldwaterq wants to merge 1 commit into
trailofbits:masterfrom
coldwaterq:fix-inst-encode-classname
Open

Fix AttributeError when encoding an INST opcode#321
coldwaterq wants to merge 1 commit into
trailofbits:masterfrom
coldwaterq:fix-inst-encode-classname

Conversation

@coldwaterq

Copy link
Copy Markdown
Contributor

Inst.encode reads self.classname, but the class defines that property as cls. There is no classname attribute, so encoding any INST opcode raises:

>>> from fickling.fickle import Inst
>>> Inst.create("os", "system").encode()
AttributeError: 'Inst' object has no attribute 'classname'

Inst.run already uses self.cls correctly, so encode is just out of step with its own class. Every other opcode round-trips through encode; INST is the only one that cannot.

Found while walking opcodes of files that are not pickles at all — a file beginning with i decodes as INST, and re-encoding it to measure how far decoding got hits this.

Change

One line in fickling/fickle.py: self.classname -> self.cls.

Test

Added TestOpcodeEncoding::test_inst_encode_round_trips to test/test_crashes.py, next to the other opcode tests. Verified it fails without the fix and passes with it.

`Inst.encode` reads `self.classname`, but the class defines the property as
`cls`. There is no `classname` attribute, so encoding any INST opcode raises:

    >>> Inst.create("os", "system").encode()
    AttributeError: 'Inst' object has no attribute 'classname'

`Inst.run` uses `self.cls` correctly, so `encode` is simply out of step with
its own class. Every other opcode round-trips through `encode`; INST is the
only one that cannot.

Added a regression test alongside the other opcode tests.
@coldwaterq
coldwaterq requested a review from ESultanik as a code owner August 27, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant