Skip to content

Pre/post checkpoint path truncates maxnextid from Long to int #5055

@WeiqunZhang

Description

@WeiqunZhang
  • Type: Correctness / Data corruption risk
  • Severity: High
  • Component: Particle checkpoint/plotfile pre-post metadata
  • Location:
    • Src/Particle/AMReX_ParticleIO.H:485
    • Src/Particle/AMReX_ParticleContainer.H:1262
    • Src/Particle/AMReX_ParticleContainer.H:1422

Problem

CheckpointPre() computes maxnextid as Long, then stores it as:

maxnextidPrePost = int(maxnextid);

The container member and getter are also int. Particle IDs are 64-bit packed IDs and can exceed 32-bit range.

Impact

  • ID truncation in pre/post write path.
  • Header can store a wrapped/incorrect next ID.
  • Restart may reset ID generator too low, risking duplicate IDs and corrupted particle identity semantics.

Suggested patch

Keep this value in Long end-to-end.

--- a/Src/Particle/AMReX_ParticleContainer.H
+++ b/Src/Particle/AMReX_ParticleContainer.H
@@
-    int GetMaxNextIDPrePost () const { return maxnextidPrePost; }
+    Long GetMaxNextIDPrePost () const { return maxnextidPrePost; }
@@
-    int maxnextidPrePost;
+    Long maxnextidPrePost;
--- a/Src/Particle/AMReX_ParticleIO.H
+++ b/Src/Particle/AMReX_ParticleIO.H
@@
-    maxnextidPrePost  = int(maxnextid);
+    maxnextidPrePost  = maxnextid;

Prepared by Codex

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions