Reading an attacker-supplied field, grid or mode basis file with hcipy runs arbitrary code as the user. read_field , read_grid and read_mode_basis pick the file format from the file name, and any name ending in pkl or pickle goes to pickle.load() . A pupil, apodizer or PSF handed over as something.pkl is opened with the same call as a .fits or .asdf one, and a pickle gadget in it executes on load. Severity is high (code execution); it is local and needs the victim to read the file.
With the default fmt=None , the three readers in hcipy/util/io.py call _guess_file_format , which maps the extension to a format:
( hcipy/util/io.py:103-104 ), and then read_field does:
( hcipy/util/io.py:262-264 ). pickle.load runs any __reduce__ callable stored in the file, so the attacker controls code execution through the file content alone. read_grid ( io.py:170-172 ) and read_mode_basis ( io.py:368-370 ) have the same branch. Pickle is one of the three formats the writers and readers document alongside asdf and fits, so it is a default, documented path and needs no option. All three readers are exported at package level ( hcipy.read_field , hcipy.read_grid , hcipy.read_mode_basis ).
Write a pickle whose payload is a benign gadget (it runs id and writes the output to a marker file), name it like a shared pupil, and read it with the public API:
/tmp/hcipy_poc.txt contains the output of id . Control: hcipy.write_field(pupil, "shared_pupil.pkl") for a 16x16 pupil Field followed by the same read_field call returns the Field and runs nothing; the file content is the only difference between the two runs. Tested on hcipy 0.7.1 (PyPI) with numpy 2.5.5, CPython 3.13, Linux; master 03af9123 has the same code.
Anyone who loads a field, grid or mode basis file from someone else is affected: pupils, apodizers, PSFs and mode bases are shared between instrument teams and published with papers, and the reader is format-agnostic. Loading one .pkl file runs code as that user with access to their files and credentials.
Do not unpickle by extension. In hcipy/util/io.py , drop pkl / pickle from _guess_file_format so the format must be requested explicitly ( fmt='pickle' ), and document in read_field , read_grid and read_mode_basis that pickle files must only be loaded from trusted sources. asdf and fits already round-trip these objects, so pickle can be deprecated for writing. The fix belongs in the shared _guess_file_format helper, which covers all three readers.
The existing IO tests that round-trip .pkl files would pass fmt='pickle' explicitly; a regression test can assert that read_field('x.pkl') raises ValueError without it.
Package: hcipy (PyPI)
Project:
Source: hcipy/hcipy/util/io.py Line 264 in 03af912 return pickle . load ( f )
hcipy/hcipy/util/io.py
Affected versions: <= 0.7.1 , master through 03af9123
Patched versions: none
Severity: CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
Dilanka Kaushal Hewage (r3vpwnx) dilankakaushalhewage@gmail.com
ehpor closed this as completed in #424 on Nov 27, 2026
