You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: [source_cell] STRU parsing silently accepts missing species mass and partial LATTICE_VECTORS; malformed coordinates/atom counts raise misleading errors #8356
Four input-validation gaps in STRU parsing, confirmed with a small driver on current develop (153ad62):
ATOMIC_SPECIES missing mass (read_atom_species.cpp): ss >> label >> mass is unchecked — a line without a mass is accepted with mass = 0, silently wrong for MD (acceleration = force / 0) and any mass-dependent path.
Partial LATTICE_VECTORS (read_atom_species.cpp): fewer than 9 components are accepted; Matrix3 default-constructs to the identity, so the unread tail keeps identity values — the cell even survives a determinant check (det = 1 in the two-row case).
Truncated coordinate line (read_atoms.cpp): ifpos >> v.x >> v.y >> v.z is unchecked; the failure is caught only deep inside parse_atom_properties() via (int)tmpid[0] < 0, which prints "mismatch in atom number" — naming the wrong problem — and calls exit(1), bypassing normal error propagation.
Non-numeric atom count (read_atoms_helper.cpp): a failed READ_VALUE leaves na = 0 and triggers the "atom number is 0 ... ignore if confident" banner; the run then fails later for the wrong stated reason.
Proposed fix (minimal, local checks only)
Check the label >> mass extraction; quit with a clear message on failure.
Read the 9 lattice-vector components with a single extraction chain; quit on failure.
Check the coordinate-triplet extraction in read_atom_positions; return false with a clear message.
Check the atom-count extraction in read_atom_type_header; return false with a clear message.
No changes to READ_VALUE itself; no behavior change for valid STRU files.
Source inspection at 153ad6290f supports all four unchecked-read problems, with two important qualifications: a bad final species count can be silently accepted, and the mass-related MD impact depends on the parser path.
Mass: the legacy species reader leaves missing mass at zero and the pseudofile at auto. UnitCell-backed MD can receive that zero mass, but pseudopotential setup may fail first. Direct lj/dp/nep/snap MD uses a separate reader that already rejects missing mass.
Coordinates: failed extraction reaches the EOF-to-char check and misleading count error on signed-char targets; that check is not portable. A short physical line can also borrow numbers from the next record. A complete final triplet ending exactly at EOF encounters a neighboring optional-property parsing bug, so a caller-only extraction check does not resolve every EOF case.
Count: after an earlier populated species, a bad last count can become zero while the total atom count stays positive, allowing parsing to succeed. Reject failed conversion while preserving intentionally supported literal-zero species.
For the proposed repair, preserve vector-row comments: one bare nine-value extraction chain would reject existing #/// row comments. Check required fields within their records and retain valid whitespace, optional coordinate properties, and successful final values at EOF. Also consume species/lattice failure returns in setup_cell; those returns are currently ignored, whereas position/header failures already propagate through ok2. Regression cases should include a bad final count after a valid species, comment-bearing vector rows, record truncation and valid EOF controls, plus bounded multi-rank failure propagation.
This is source-supported diagnosis; the reported driver, full MD behavior and MPI termination were not reproduced. PR #8355 addresses only overlapping lattice validation and does not resolve this issue.
Thanks for the source confirmation and the two qualifications — they matched what the local probes showed. All four unchecked-read problems are addressed in #8361 (merged at e2b9082): the ATOMIC_SPECIES mass, LATTICE_VECTORS component count, species-declaration count, and per-species atom-count reads are now validated with diagnostics, and the merged test suite covers each rejection path.
Activity
ABACUS-PR-BOT commentedon Nov 21, 2026
Source inspection at
153ad6290fsupports all four unchecked-read problems, with two important qualifications: a bad final species count can be silently accepted, and the mass-related MD impact depends on the parser path.auto. UnitCell-backed MD can receive that zero mass, but pseudopotential setup may fail first. Directlj/dp/nep/snapMD uses a separate reader that already rejects missing mass.29bfe6660f.charcheck and misleading count error on signed-char targets; that check is not portable. A short physical line can also borrow numbers from the next record. A complete final triplet ending exactly at EOF encounters a neighboring optional-property parsing bug, so a caller-only extraction check does not resolve every EOF case.For the proposed repair, preserve vector-row comments: one bare nine-value extraction chain would reject existing
#///row comments. Check required fields within their records and retain valid whitespace, optional coordinate properties, and successful final values at EOF. Also consume species/lattice failure returns insetup_cell; those returns are currently ignored, whereas position/header failures already propagate throughok2. Regression cases should include a bad final count after a valid species, comment-bearing vector rows, record truncation and valid EOF controls, plus bounded multi-rank failure propagation.This is source-supported diagnosis; the reported driver, full MD behavior and MPI termination were not reproduced. PR #8355 addresses only overlapping lattice validation and does not resolve this issue.
Fix(cell): validate core STRU fields against malformed input (#8361)
DanielZhao0432 commentedon Nov 22, 2026
Thanks for the source confirmation and the two qualifications — they matched what the local probes showed. All four unchecked-read problems are addressed in #8361 (merged at e2b9082): the ATOMIC_SPECIES mass, LATTICE_VECTORS component count, species-declaration count, and per-species atom-count reads are now validated with diagnostics, and the merged test suite covers each rejection path.