Hi,
Source: coreutils master 35492ca115 (2026-11-14); src/expand-common.c is
unchanged since.
set_extend_size() and set_increment_size() (src/expand-common.c:97-131)
detect a second "/" or "+" specifier by testing the stored value (if
(extend_size), if (increment_size)) rather than whether a specifier was
already seen. A first specifier with value 0 leaves the size at 0, so the
documented error never fires. The same test in validate_tab_stops()
(increment_size && extend_size) lets /0 and +5 be combined:
$ expand -t '/0,5' </dev/null; echo $? # 0 (expected: '/' specifier only
allowed with the last value, 1)
$ expand -t '/0 /5' </dev/null; echo $? # 0
$ expand -t '+0,+5' </dev/null; echo $? # 0 (expected: '+' specifier only
allowed with the last value, 1)
$ expand -t '/0,+5' </dev/null; echo $? # 0 (expected: '/' specifier is
mutually exclusive with '+', 1)
$ expand -t '/8,4' </dev/null; echo $? # 1 expand: '/' specifier only
allowed with the last value
For example, printf 'a\tb\tc\n' | expand -t '/0,5' silently behaves as -t
/5. unexpand shares the code.
The attached fix.patch tracks the specifiers with extend_seen and
increment_seen flags, uses them in the three checks, and adds three cases
(e8, e9, e10) to tests/expand/
https://www.google.com/url?q=http://expand.pl&source=gmail&ust=1794997766975000&sa=E.
With it, make check TESTS="tests/expand/
https://www.google.com/url?q=http://expand.pl&source=gmail&ust=1794997766975000&sa=E
tests/unexpand/
https://www.google.com/url?q=http://unexpand.pl&source=gmail&ust=1794997766975000&sa=E
tests/expand/bounded-memory.sh tests/unexpand/bounded-memory.sh" passes,
and the new cases fail on the unpatched binary.
A lone /0 is still accepted and means "no extension", as now; whether /0
should be rejected like a plain 0 is a separate question.
Found by an LLM-assisted tool, verified manually.
Regards,
Martin Mirchev
--- a/src/expand-common.c
+++ b/src/expand-common.c
@@ -93,12 +93,17 @@
set_max_column_width (column_width);
}
+/* Whether a '/' or '+' specifier has been seen; the sizes alone cannot
+ tell, as a specified value of 0 leaves them at 0. */
+static bool extend_seen;
+static bool increment_seen;
+
static bool
set_extend_size (colno tabval)
{
bool ok = true;
- if (extend_size)
+ if (extend_seen)
{
error (0, 0,
_("'/' specifier only allowed"
@@ -106,6 +111,7 @@
ok = false;
}
extend_size = tabval;
+ extend_seen = true;
set_max_column_width (extend_size);
@@ -117,7 +123,7 @@
{
bool ok = true;
- if (increment_size)
+ if (increment_seen)
{
error (0,0,
_("'+' specifier only allowed"
@@ -125,6 +131,7 @@
ok = false;
}
increment_size = tabval;
+ increment_seen = true;
set_max_column_width (increment_size);
@@ -252,7 +259,7 @@
prev_tab = tabs[i];
}
- if (increment_size && extend_size)
+ if (increment_seen && extend_seen)
error (EXIT_FAILURE, 0, _("'/' specifier is mutually exclusive with '+'"));
}
--- a/tests/expand/expand.pl
+++ b/tests/expand/expand.pl
@@ -184,6 +184,13 @@
{ERR => "$prog: '/' specifier only allowed with the last value\n"}],
['e7', '--tabs=3/', {IN=>''}, {OUT=>''}, {EXIT=>1},
{ERR => "$prog: '/' specifier not at start of number: '/'\n"}],
+ # A '/' or '+' value of 0 used to hide a later specifier.
+ ['e8', '--tabs=/0,5', {IN=>''}, {OUT=>''}, {EXIT=>1},
+ {ERR => "$prog: '/' specifier only allowed with the last value\n"}],
+ ['e9', '--tabs=+0,+5', {IN=>''}, {OUT=>''}, {EXIT=>1},
+ {ERR => "$prog: '+' specifier only allowed with the last value\n"}],
+ ['e10', '--tabs=/0,+5', {IN=>''}, {OUT=>''}, {EXIT=>1},
+ {ERR => "$prog: '/' specifier is mutually exclusive with '+'\n"}],
# A bare '-' is standard input.
['stdin-dash', '-', {IN_PIPE=>"stdin\n"}, {IN=>{f=>"file\n"}},