deepmodeling / deepmodeling/fpop
[Code scan] Make RunAbacus input-file discovery restore cwd on parse failures
- Dominant language
- Python
- Stars
- 3
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
This issue is a result of a Codex global code scan of `deepmodeling/fpop` at commit `b05b337590c31a5237b2dcbd9c0833b841c08cd4`.
Relevant code:
https://github.com/deepmodeling/fpop/blob/b05b337590c31a5237b2dcbd9c0833b841c08cd4/fpop/abacus.py#L249-L305
https://github.com/deepmodeling/fpop/blob/b05b337590c31a5237b2dcbd9c0833b841c08cd4/fpop/abacus.py#L556-L596
Problem:
`RunAbacus.input_files()` changes the process working directory with `os.chdir(task_path)` and restores it only on the successful path. If STRU parsing raises, the caller is left in the task directory.
There are at least two easy ways to trigger this:
1. If `STRU` is missing, `get_pporbdpks_from_stru("STRU")` returns `{}`. `input_files()` checks `if stru_data != None`, then indexes `stru_data["orb"]` and raises `KeyError`.
2. If a STRU section header has an inline comment, such as `NUMERICAL_ORBITAL # comment`, `get_block()` does not strip comments when detecting the next section header. The commented header is treated as an `ATOMIC_SPECIES` data line and parsing can fail with `ValueError: could not convert string to float: '#'`.
Minimal reproduction for the second case:
```text
ATOMIC_SPECIES
H 1 H.upf
NUMERICAL_ORBITAL # comment
H.orb
LATTICE_CONSTANT
1
```
Expected behavior:
`RunAbacus.input_files()` should restore cwd in a `finally` block, and STRU parsing failures should be reported as clear missing/invalid input errors instead of leaking process state.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.