Repository navigation
Parse params.py with ast instead of exec in read_python - #4916
Merged
Merged
Conversation
alejoe91
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
read_python()(core/core_tools.py) parsed a Python-style config file byexec()-ing its contents. That means reading a Phy/Kilosort folder (viaPhySortingExtractor/read_phy, which readsparams.py) or a Klusta config executes whatever is in that file. Since these outputs are routinely shared and downloaded, andparams.pyis expected to be a simple dictionary of values (sample_rate, n_channels, ...), this replaces theexecwith a smallast-based parser that evaluates only literal assignments (numbers/strings/bools/None/list/tuple/dict, plusrange()/list(range())with integer args) and ignores everything else.Why
We don't need to exec the params since it's a simple dictionary; this avoids executing arbitrary code from a params/config file.
Changes
read_python()rewritten to parse viaast(noexec). Fixes both the phy and klusta call sites. A realisticparams.pyparses unchanged; aparams.pycontaining e.g.import os; os.system(...)is no longer executed.core/tests/test_read_python_safe.py): a config with a side-effecting line is not executed, and the reader's source contains noexec/eval.Note
I used Claude Code as an assistant to investigate and prepare this fix; I reviewed the analysis, the change, and the test before submitting.