From 57b9d1a58a9eb30feec72b0ccce6bdfd5e1ef92e Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Mon, 30 Mar 2026 18:20:09 +1300 Subject: [PATCH] Test rejection of pax extended tar files. Also change 852de579's shell invocation to use NUL on Windows instead of /dev/null, per feedback from Andrew Dunstan. That command wasn't expected to succeed on Windows, but the similar usage added here might. --- src/bin/pg_waldump/t/001_basic.pl | 42 +++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index ce1f6aa30c0..3b99a8f6d4f 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -5,6 +5,7 @@ use strict; use warnings FATAL => 'all'; use Cwd; use File::Copy; +use File::Spec; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; @@ -13,12 +14,14 @@ use List::Util qw(shuffle); my $tar = $ENV{TAR}; my @tar_c_flags; -# By default, bsdtar archives sparse files in GNU tar's --format=posix --sparse -# format, so pg_waldump can't find files that ZFS has decided to store with -# holes. Turn that off. -if (system("$tar --no-read-sparse -c - /dev/null > /dev/null") == 0) +my $devnull = File::Spec->devnull(); + +# By default, bsdtar archives sparse files in GNU tar's --format=pax --sparse +# format, so pg_waldump rejects WAL that ZFS has decided to store with holes. +# Turn that off. +if (system("$tar --no-read-sparse -c $devnull > $devnull") == 0) { - push(@tar_c_flags, "--no-read-sparse"); + push(@tar_c_flags, "--no-read-sparse"); } program_help_ok('pg_waldump'); @@ -339,7 +342,7 @@ sub test_pg_waldump # Create a tar archive, shuffle the file order sub generate_archive { - my ($archive, $directory, $compression_flags) = @_; + my ($archive, $directory, $compression_flags, @extra_flags) = @_; my @files; opendir my $dh, $directory or die "opendir: $!"; @@ -355,7 +358,7 @@ sub generate_archive # move into the WAL directory before archiving files my $cwd = getcwd; chdir($directory) || die "chdir: $!"; - command_ok([$tar, @tar_c_flags, $compression_flags, $archive, @files]); + command_ok([$tar, @extra_flags, @tar_c_flags, $compression_flags, $archive, @files]); chdir($cwd) || die "chdir: $!"; } @@ -477,4 +480,29 @@ for my $scenario (@scenarios) } } +SKIP: +{ + skip "tar command is not available", 1 + if !defined $tar; + + skip "tar command doesn't understand --format=pax", 1 + if system("$tar --format=pax -c " . + $node->data_dir . "/pg_wal/* > $devnull") != 0; + + generate_archive($tmp_dir . '/pg_wal_pax.tar', + $node->data_dir . '/pg_wal', + '-cf', + ("--format=pax")); + + command_fails_like( + [ + 'pg_waldump', + '--path' => $tmp_dir . '/pg_wal_pax.tar', + '--start' => $start_lsn, + '--end' => $end_lsn, + ], + qr/error: pax extensions to tar format are not supported/, + 'fails if pax extended header is detected'); +} + done_testing(); -- 2.52.0