Backport request: Windows GRO trajectory fix (450256fc) missing from release-2025/2026

GROMACS version: 2024.4 (native MSVC build; the affected code is identical in release-2025 / release-2026)

GROMACS modification: No (this report is about unmodified upstream code — I only applied a local fix after diagnosing the bug)

Hi all,

I ran into a Windows-specific bug in the GRO reader, and while diagnosing it I

found that `main` already contains a fix for exactly this problem

(`450256fc`, May 2026, "Fixed GRO trajectory EOF detection on Windows with

MinGW") — but that fix is not in `release-2025` / `release-2026`, so current

release builds are still affected. Would a backport be possible?

**The bug.** On Windows (MSVC and MinGW alike), reading any multi-frame `.gro`

file as a trajectory fails deterministically with:

```

Fatal error:

gro file does not have the number of atoms on the second line

```

Single-frame `.gro` files (e.g. structure input for `editconf`) are unaffected,

which is why most workflows never hit it.

**Root cause.** `gmx_one_before_eof()` in `src/gromacs/fileio/groio.cpp` peeks

one byte and rewinds with `gmx_fseek(fp, -1, SEEK_CUR)` on a text-mode stream.

The C standard only guarantees relative seeks on text streams for offset 0 or a

value previously returned by `ftell`; the Windows CRT rejects this one with

EINVAL, and the corrupted stream state then produces the misleading "number of

atoms" error. This matches the analysis in `450256fc`.

**Where it still is.** I checked the branch sources: `release-2025`,

`release-2026` (and `release-2024`) still contain the old `gmx_one_before_eof()`

with the backward relative seek; `main` no longer has the function.

**Impact.** `trjconv`, `rms`, `check` and anything else that reads `.gro`

trajectories fails on Windows; 15+ unit tests fail as well (MdrunIOTests,

ToolUnitTests, CoordinateIOTests, TrajectoryAnalysisUnitTests,

MdrunTestsOneRank/TwoRanks, MdrunMpiTests).

**Possible fixes.** Backport `450256fc` from `main`; or apply the minimal patch

attached to this post (`ungetc()` instead of the backward seek — valid in both

text and binary mode on every platform). I verified the attached patch on a

native MSVC build of 2024.4: `trjconv`/`rms`/`check` work with multi-frame

`.gro` input and all previously failing unit tests pass.

**Why I am posting here instead of filing an issue.** I could not create a

GitLab account: GitLab’s phone verification is not available in China (their

docs list it as unsupported) and I have no credit card for the alternative

verification path. I also could not post this in the Developers discussions

category, as it is read-only for non-members. If someone could file this on

GitLab, or handle the backport directly, that would be much appreciated — I am

happy to provide any additional information or to test a fix.

(Attachment: 0001-fix-gmx_one_before_eof-textmode-seek.patch.txt — the same patch, renamed with a .txt extension because the forum restricts upload extensions)

0001-fix-gmx_one_before_eof-textmode-seek.patch.txt (671 Bytes)