A Crystal Structure File Should Not Run Code
The CIF parser in diffpy.structure used eval() on the symmetry-operation string from the file, so a malicious CIF file could run arbitrary Python code when loaded. An attacker could achieve remote code execution with the privileges of the user opening the file.
Published on r3vpwnx.medium.com
Cybersecurity
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
A CIF file is the standard way crystallographers exchange a crystal structure. It carries the unit cell, the atoms, and the symmetry operations that generate the rest of the lattice from the asymmetric unit. Those symmetry operations are written as short algebraic strings such as x,-y,z+1/2.
diffpy.structure, part of the DiffPy stack used across materials science and condensed-matter work, has to turn each of those strings into a function that maps one fractional coordinate to another. The parser lives in src/diffpy/structure/parsers/p_cif.py, and the function that does the conversion is get_symop().

The problem is how get_symop() did the conversion: it took the symmetry-operation string straight from the file and evaluated it as a Python expression with eval(). For a well-formed operation that produces the right result. But eval() has no idea it is only supposed to see x,-y,z+1/2; it will run whatever expression it is handed. A CIF file whose symmetry-operation field contains a Python payload instead of a lattice operation runs that payload with the privileges of whoever loaded the file.
Setup
The write-up does not describe a lab environment, tooling, or a specific version of diffpy.structure beyond the fact that the flaw was fixed in 3.5.1. The precondition is simply that a victim loads an attacker-supplied .cif file through the library's CIF parser.
Finding it
The symmetry-operation field, a value that comes from the file and is therefore attacker-controlled, was being passed to eval(). That is wrong because the field has a tiny, closed grammar: the variables x, y and z, rational coefficients, and plus and minus signs. Nothing in that grammar requires a general-purpose expression evaluator, and a general-purpose evaluator accepts far more than the grammar does.
Exploitation
Step 1: Put a Python expression in the symmetry-operation field
The symmetry-operation field of a CIF file is where the payload goes. Instead of a lattice operation such as x,-y,z+1/2, the field contains a Python expression. When the file is parsed, get_symop() reads that string and passes it to eval(), which executes it.
Step 2: Get the file loaded
The payload runs when the victim opens the file with diffpy.structure. The report does not show a specific payload string, a request, a command, or a captured response; it describes the mechanism rather than a worked exploit transcript.
Root cause
get_symop() in src/diffpy/structure/parsers/p_cif.py evaluates a file-supplied string with eval(). This is CWE-95, eval injection. eval() does not enforce that the field looks like an expression: it executes any valid Python expression it is given.
Impact
A crafted CIF file gives the attacker code execution with the privileges of whoever loads it. The report frames the exposure in terms of how CIF files are actually handled: they are downloaded from structure databases, exported by other tools, attached to papers, and passed between collaborators. Loading one is routine and is not supposed to be a security decision, which is exactly why the trust boundary is the wrong place to rely on.
Fix
The maintainers fixed the issue in version 3.5.1. The guidance it gives is to parse the symmetry operation with code that understands its small grammar and nothing else, or to map the handful of legal tokens directly, rather than handing a field from a file to eval() just because the field usually looks like an expression.
Variants to test
- Other scientific and domain-specific file formats whose fields look like expressions: check whether any parser passes a field to
eval(),exec(),compile()or a template engine. A positive result is a file that executes code when parsed. - Other functions in the same parser module that transform file-supplied strings: look for sibling helpers that build callables from file content. A positive result is any path from file bytes to executed code.
- Downstream tools that embed diffpy.structure and accept uploaded or shared structure files: check whether they run the parser on untrusted input and with what privileges. A positive result is a service that parses an attacker-supplied CIF in a privileged context.
CVE record: https://www.cve.org/CVERecord?id=CVE-2026-133708
Write-up: https://r3vpwnx.space/research/diffpy-structure-cif-eval-rce
What happened, in plain words
A piece of scientific software called diffpy.structure reads crystal structure files. One of the fields in those files is supposed to contain a short piece of maths, something like x,-y,z+1/2. The software took that field and handed it to a Python feature called eval(), which runs whatever text it is given as if it were a program. So a file that put a Python program in that field instead of maths would have that program run on the computer of whoever opened the file. The flaw is tracked as CVE-2026-133708 and was fixed in version 3.5.1.
That is the whole story. The rest of this article explains the pieces one at a time: what a CIF file is, what diffpy.structure does with it, what eval() is and why using it here is dangerous, and why files like this should never be trusted.
Context
What a CIF file is
A CIF file (Crystallographic Information File) is the standard way crystallographers exchange a crystal structure. Think of it as a recipe card for a crystal: it records the unit cell (the repeating box that the crystal is built from), the atoms inside that box, and the symmetry operations that generate the rest of the lattice from the asymmetric unit.
Two of those terms need a moment:
- The asymmetric unit is the smallest part of the structure you need to describe; the rest can be generated from it by repeating and mirroring.
- A symmetry operation is the instruction for that repeating and mirroring. It is written as a short algebraic string, for example
x,-y,z+1/2. Read it as: take the x coordinate as it is, flip the sign of the y coordinate, and add one half to the z coordinate. That maps one point in the crystal to another equivalent point.
What diffpy.structure does
diffpy.structure is part of the DiffPy stack, a collection of tools used across materials science and condensed-matter work. Its job includes reading a CIF file and turning each symmetry-operation string into a function that maps one fractional coordinate to another. A fractional coordinate is a position expressed as a fraction of the unit cell's edges rather than in metres, which is convenient because the same numbers work for any crystal size.
The parser lives in src/diffpy/structure/parsers/p_cif.py, and the function that does the conversion is get_symop(). A parser is the part of a program that reads a file and turns its text into usable data; a function is a named block of code that does one job when called.

The image is the header of the write-up: the title "A Crystal Structure File Should Not Run Code", the author Dilanka Kaushal Hewage (r3vpwnx), and the one-line summary that parsing a CIF file's symmetry operations with eval() turned opening a .cif into RCE in diffpy.structure (CVE-2026-133708).
The problem
The problem is how get_symop() did the conversion: it took the symmetry-operation string straight from the file and evaluated it as a Python expression with eval(). For a well-formed operation that produces the right result. But eval() has no idea it is only supposed to see x,-y,z+1/2; it will run whatever expression it is handed. A CIF file whose symmetry-operation field contains a Python payload instead of a lattice operation runs that payload with the privileges of whoever loaded the file.
Unpacking that last sentence:
- A Python expression is a piece of Python code that produces a value, such as
2 + 3orx * 2. - A payload is the part of an attack that actually does the damage, here the code hidden in the file.
- Privileges are the permissions a program is running with. If you opened the file as your normal user, the payload runs as your normal user: it can read your files, and do anything else you could do.
Setup
The write-up does not describe a lab environment, tooling, or a specific version of diffpy.structure beyond the fact that the flaw was fixed in 3.5.1. The precondition is simply that a victim loads an attacker-supplied .cif file through the library's CIF parser.
In plain terms: there is no special setup to reproduce this. The only thing that has to happen is that someone opens a CIF file that came from an attacker, using software that relies on diffpy.structure to read it.
Finding it
The symmetry-operation field, a value that comes from the file and is therefore attacker-controlled, was being passed to eval(). That is wrong because the field has a tiny, closed grammar: the variables x, y and z, rational coefficients, and plus and minus signs. Nothing in that grammar requires a general-purpose expression evaluator, and a general-purpose evaluator accepts far more than the grammar does.
Some of those words are worth slowing down for:
- Attacker-controlled means the value is chosen by whoever made the file, not by the program. If you can write the file, you can write that field.
- A grammar is the set of rules that says which strings are valid. The grammar here is tiny: only the letters
x,yandz, numbers written as fractions, and+and-signs. A closed grammar means nothing outside those rules is allowed. - A rational coefficient is a number written as a fraction, such as
1/2. - A general-purpose expression evaluator is a tool that can run any valid expression in a language, not just the small set you had in mind. It is like hiring a translator who speaks every language when all you needed was someone to read out three letters.
The mismatch is the bug. The field only ever needs to express a handful of legal shapes, but eval() will happily accept anything Python understands.
Exploitation
Step 1: Put a Python expression in the symmetry-operation field
The symmetry-operation field of a CIF file is where the payload goes. Instead of a lattice operation such as x,-y,z+1/2, the field contains a Python expression. When the file is parsed, get_symop() reads that string and passes it to eval(), which executes it.
Why this step works: the program treats the field as data, but eval() treats it as code. The attacker only has to write the field, which is ordinary text in a file they are already sending.
Step 2: Get the file loaded
The payload runs when the victim opens the file with diffpy.structure. The report does not show a specific payload string, a request, a command, or a captured response; it describes the mechanism rather than a worked exploit transcript.
Why this step matters: the attack needs a person or a service to load the file. That is not a high bar, because loading CIF files is routine work in this field.
Root cause
get_symop() in src/diffpy/structure/parsers/p_cif.py evaluates a file-supplied string with eval(). This is CWE-95, eval injection. eval() does not enforce that the field looks like an expression: it executes any valid Python expression it is given.
A few terms:
- Root cause is the underlying mistake that makes the attack possible, as opposed to its symptoms.
- CWE-95 is a catalogue entry for a class of weakness: code injection through
eval(). CWE stands for Common Weakness Enumeration, a public list of software weakness types. - Injection in general means slipping something into a place where the program expected only data, so that the program treats it as instructions. The everyday comparison is a form where you write your name and someone writes a command instead, and the system runs it.
Impact
A crafted CIF file gives the attacker code execution with the privileges of whoever loads it. The report frames the exposure in terms of how CIF files are actually handled: they are downloaded from structure databases, exported by other tools, attached to papers, and passed between collaborators. Loading one is routine and is not supposed to be a security decision, which is exactly why the trust boundary is the wrong place to rely on.
Two ideas to unpack:
- Code execution means the attacker's instructions run on the victim's machine, with the victim's permissions.
- A trust boundary is the line between what a system treats as safe and what it treats as suspect. Loading a CIF file is routine and is not supposed to be a security decision.
Fix
The maintainers fixed the issue in version 3.5.1. The guidance it gives is to parse the symmetry operation with code that understands its small grammar and nothing else, or to map the handful of legal tokens directly, rather than handing a field from a file to eval() just because the field usually looks like an expression.
In everyday terms: instead of a translator who speaks every language, use a checker that only accepts the three letters, the fractions and the signs, and rejects everything else. A token here means one of the small legal pieces of the string, such as x or +1/2.
Variants to test
- Other scientific and domain-specific file formats whose fields look like expressions: check whether any parser passes a field to
eval(),exec(),compile()or a template engine. A positive result is a file that executes code when parsed. - Other functions in the same parser module that transform file-supplied strings: look for sibling helpers that build callables from file content. A positive result is any path from file bytes to executed code.
- Downstream tools that embed diffpy.structure and accept uploaded or shared structure files: check whether they run the parser on untrusted input and with what privileges. A positive result is a service that parses an attacker-supplied CIF in a privileged context.
What those variants mean:
exec()andcompile()are other Python features that turn text into running code, so the same mistake can appear through them.- A template engine fills in placeholders in a document; if it evaluates what it fills in, it can be abused the same way.
- A callable is anything you can call like a function.
- Downstream tools are other programs that build on diffpy.structure. If such a tool accepts uploaded CIF files and parses them on a server, the payload runs on the server rather than on a user's laptop, which is a more serious position for an attacker.
CVE record: https://www.cve.org/CVERecord?id=CVE-2026-133708
Write-up: https://r3vpwnx.space/research/diffpy-structure-cif-eval-rce
Glossary
- Asymmetric unit: the smallest part of a crystal structure from which the whole structure can be generated by symmetry.
- Attacker-controlled: a value chosen by whoever supplies the input, not by the program.
- Callable: anything in Python that can be called like a function.
- CIF file: Crystallographic Information File, the standard text format for exchanging crystal structures.
- Closed grammar: a set of rules that allows only a small, fixed set of strings and nothing else.
- Code execution: running an attacker's instructions on a victim's machine with the victim's permissions.
- compile(): a Python function that turns source text into code objects.
- CVE: Common Vulnerabilities and Exposures, a public identifier for a specific security flaw.
- CWE: Common Weakness Enumeration, a public catalogue of weakness types.
- CWE-95: the catalogue entry for eval injection, code injection through
eval(). - diffpy.structure: a Python library in the DiffPy stack that reads and works with crystal structure files.
- Downstream tool: software that builds on another library and uses it internally.
- eval(): a Python function that runs a string as a Python expression and returns its value.
- exec(): a Python function that runs a string as Python statements.
- Fractional coordinate: a position expressed as a fraction of the unit cell's edges.
- Function: a named block of code that performs one job when called.
- General-purpose expression evaluator: a tool that can run any valid expression in a language, not just a restricted set.
- Grammar: the rules that define which strings are valid in a format.
- Injection: slipping instructions into a place where the program expected only data.
- Parser: the part of a program that reads a file and turns its text into usable data.
- Payload: the part of an attack that carries out the harmful action.
- Privileges: the permissions a program or user has, which limit what code can do.
- Python expression: a piece of Python code that produces a value.
- Rational coefficient: a number written as a fraction, such as
1/2. - RCE: remote code execution, running code on a machine you do not control directly.
- Root cause: the underlying mistake that makes an attack possible.
- Symmetry operation: an instruction, written as a short algebraic string, that maps one point in a crystal to an equivalent point.
- Template engine: software that fills placeholders in a document with values.
- Token: one of the small legal pieces of a string, such as
xor+1/2. - Trust boundary: the line between what a system treats as safe and what it treats as suspect.
- Unit cell: the repeating box that a crystal is built from.