Skip to content

Bug: [source_cell] STRU parsing silently accepts missing species mass and partial LATTICE_VECTORS; malformed coordinates/atom counts raise misleading errors #8356

Closed

Description

@DanielZhao0432

Problem

Four input-validation gaps in STRU parsing, confirmed with a small driver on current develop (153ad62):

  1. 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.
  2. 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).
  3. 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.
  4. 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.

Activity

  1. added
    Bugs
    on Nov 21, 2026
  2. ABACUS-PR-BOT commented on Nov 21, 2026

    @ABACUS-PR-BOT
    Collaborator

    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.
    • Vectors: two identity rows can retain the default third row, so determinant validation does not establish that all components were read. This remains present at PR Fix(cell): require LATTICE_PARAMETERS for non-cubic named lattices #8355 head 29bfe6660f.
    • 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.

  3. DanielZhao0432 commented on Nov 22, 2026

    @DanielZhao0432
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions