Fix: validate cube file parsing before copying charge data (#7563), in addition #6458 is fixed - #8023
Merged
Merged
Conversation
…ing#7563) read_vdata_palgrid() ignored the bool return of read_cube() and used the parsed dimensions and data unconditionally, so a malformed or truncated cube file could lead to out-of-bounds access in memcpy or trilinear_interpolate(). - read_cube() now checks the stream state after each parsing stage, rejects negative natom and non-positive grid dimensions, guards the nx*ny*nz product against int overflow, and returns false if any expected value is missing. - read_vdata_palgrid() checks the return value, logs a warning, and propagates the failure to its caller. - Add test_read_cube.cpp covering valid files, truncated data, invalid dimensions, negative natom, and failure propagation through read_vdata_palgrid(). Verification: cmake --build build --target MODULE_IO_read_cube MODULE_IO_rho_io; OMP_NUM_THREADS=1 ctest -V -R "MODULE_IO_read_cube|MODULE_IO_rho_io" (10/10 passed); agent_governance_check.py --staged (no blocking findings; docs update not required, no INPUT behavior change).
ModuleIO::read_vdata_palgrid previously returned false on the root rank when the cube file was missing or malformed, while the other ranks entered Parallel_Grid::bcast() and blocked in MPI_Recv waiting for data that would never be sent. Replace the early returns with ModuleBase::WARNING_QUIT so the run terminates on every rank. This makes the bool error code meaningless, so remove the now-dead fallback paths that depended on it: the nspin=2/4 "rearrange electron density later" branch, the meta-GGA tau TF fallback, the atomic-rho fallback for failed file reads, and the read_error/read_kin_error plumbing in Charge::init_rho. Update the unit test to expect death on a malformed cube file.
AsTonyshment
approved these changes
Sep 26, 2026
…x.md The online documentation for hs_matrix.md only described the new (develop) filenames for Hamiltonian/overlap matrix output, which confused LTS users. Add explicit notes mapping out_hsk to the LTS keyword out_mat_hs (files data-0-H, data-0-S) and out_hsr to the LTS keyword out_mat_hs2 (files data-HR-sparse_SPIN0.csr, data-SR-sparse_SPIN0.csr). Fixes deepmodeling#6458
… files Commit 6601fb6 made a failed cube read abort instead of hanging non-root ranks, but in doing so it dropped the init_chg=auto semantics: when no density file exists, auto must silently fall back to the atomic density. This broke ASE/abacuslite MD, whose first ionic step legitimately runs in a fresh directory with no charge file and relies on that fallback. read_rho_file/read_kin_file now probe for the cube file on the parsing rank and broadcast the result with Parallel_Common::bcast_bool, so all ranks agree to skip together (no MPI hang) instead of aborting inside read_vdata_palgrid. init_rho aborts only for init_chg=file; auto falls back to atomic density (and TF tau for meta-GGA). Add regression tests for both paths. Verified: cmake --build build --target elecstate passes; agent_governance_check.py --base HEAD --head HEAD reports no findings.
7 tasks done
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.
Fix #7563 and #6458
read_vdata_palgrid() ignored the bool return of read_cube() and used the parsed dimensions and data unconditionally, so a malformed or truncated cube file could lead to out-of-bounds access in memcpy or trilinear_interpolate().
Verification: cmake --build build --target MODULE_IO_read_cube MODULE_IO_rho_io; OMP_NUM_THREADS=1 ctest -V -R
"MODULE_IO_read_cube|MODULE_IO_rho_io" (10/10 passed); agent_governance_check.py --staged (no blocking findings; docs update not required, no INPUT behavior change).
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
Fix #
Unit Tests and/or Case Tests for my changes
What's changed?
Governance Notes