pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 1548140642@qq.com
Subject: BUG #19868: pg_resetwal prints uint32 WAL segment size as -1 bytes
Date: Wed, 11 Nov 2026 05:48:24 +0000
Message-ID: <19868-5efb930ace5bd191@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19868
Logged by:          Milo
Email address:      1548140642@qq.com
PostgreSQL version: 18.6
Operating system:   Linux/amd64
Description:        

When pg_resetwal -n reads a damaged pg_control whose uint32 xlog_seg_size
field contains 4294967295, its invalid-WAL-segment-size warning prints "-1
bytes". The diagnostic should preserve the unsigned field value and print
"4294967295 bytes".

How to repeat:

On the tested PostgreSQL 18 x86-64 build, save the following as
reproducer.sh:

```sh
#!/bin/sh
set -eu

d=$(mktemp -d)
trap 'rm -rf "$d"' EXIT
mkdir -p "$d/global" "$d/pg_wal"
cp "$PGDATA/global/pg_control" "$d/global/pg_control"
printf '18\n' > "$d/PG_VERSION"
printf '\377\377\377\377' |
  dd of="$d/global/pg_control" bs=1 seek=228 conv=notrunc 2>/dev/null
/usr/lib/postgresql/18/bin/pg_resetwal -n -D "$d" 2>&1 || true
```

Run it with PGDATA naming a PostgreSQL 18 data directory:

```sh
sh reproducer.sh
```

The script modifies only the isolated copy. The relevant output is:

```
pg_resetwal: warning: pg_control exists but has invalid CRC; proceed with
caution
pg_resetwal: warning: pg_control specifies invalid WAL segment size (-1
bytes); proceed with caution
```

For this build, offset 228 is the xlog_seg_size field. The four bytes
written there represent UINT32_MAX, or 4294967295, so the second warning
renders the unsigned value as signed.

The issue was reproduced on PostgreSQL 18.6 (Debian 18.6-1.pgdg13+2),
64-bit, on Linux/amd64. Source inspection of PostgreSQL 20devel also shows
that the uint32 ControlFile.xlog_seg_size value is passed to ngettext format
strings using %d; PostgreSQL 20devel was not tested in a recorded runtime
execution. This occurs when pg_resetwal diagnoses an invalid WAL segment
size stored in a damaged control file.








view thread (2+ messages)  latest in thread

Message-ID: <19868-5efb930ace5bd191@postgresql.org>
Permalink:  ../19868-5efb930ace5bd191@postgresql.org/
Also on:    postgresql.org/message-id/19868-5efb930ace5bd191@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, 1548140642@qq.com
  Subject: Re: BUG #19868: pg_resetwal prints uint32 WAL segment size as -1 bytes
  In-Reply-To: <19868-5efb930ace5bd191@postgresql.org>
  References: <19868-5efb930ace5bd191@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox