[Code scan] Truncate rewritten training JSON after HDF5 conversion
This issue is from a Codex global scan of the repository.
`convert_training_data_to_hdf5()` can leave stale bytes at the end of rewritten JSON input files.
Evidence:
https://github.com/deepmodeling/dpgen/blob/7af52460e1a5bc0edeb5e19cf92af5a6c79f90ec/dpgen/util.py#L119-L142
The function opens input JSON files with `r+`, updates the training system paths, calls `f.seek(0)`, and writes the new JSON with `json.dump()`. It never calls `f.truncate()`. If the rewritten JSON is shorter than the original file, trailing bytes from the old content remain and the JSON file can become invalid.
Expected behavior: truncate the file after writing, or write to a temporary file and replace the original atomically.
0 条评论