Summary
%j (day of year) has a default width of 3. When the user requests a narrower width via %02j, GNU pads the value to the requested width (01 for day 1), while uutils strips leading zeros entirely and emits 1.
The same family of bugs likely affects other wide-default specifiers (%Y, %G).
Found by a fuzz_date run.
Reproduction
$ LC_ALL=C TZ=UTC /usr/bin/date -d '2024-01-01' '+%02j'
01
$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '2024-01-01' '+%02j'
1
$ LC_ALL=C TZ=UTC /usr/bin/date -d '2024-01-09' '+%02j'
09
$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '2024-01-09' '+%02j'
9
When the natural representation is already >= the requested width, both agree.
Test
#[test]
fn test_date_strftime_narrow_width_on_wide_default() {
new_ucmd!()
.env("LC_ALL", "C")
.env("TZ", "UTC")
.arg("-d")
.arg("2024-01-01")
.arg("+%02j")
.succeeds()
.stdout_is("01\n");
}
Summary
%j(day of year) has a default width of 3. When the user requests a narrower width via%02j, GNU pads the value to the requested width (01for day 1), whileuutilsstrips leading zeros entirely and emits1.The same family of bugs likely affects other wide-default specifiers (
%Y,%G).Found by a
fuzz_daterun.Reproduction
When the natural representation is already >= the requested width, both agree.
Test