Skip to content

head, tail: reject invalid count values even when overridden - #16038

Open
Logic769 wants to merge 6 commits into
uutils:mainfrom
Logic769:head-tail-validate-overridden-counts
Open

Logic769 wants to merge 6 commits into
uutils:mainfrom
Logic769:head-tail-validate-overridden-counts

Conversation

@Logic769

Copy link
Copy Markdown
Contributor

Problem

GNU validates every -c/-n value even when a later one overrides it: head -c1-3 -n1 reports invalid number of bytes: '1-3' and exits 1, while uutils only parsed the surviving value and printed the input. tail --bytes 1,2 --lines 2 had the same problem.

Change

Extract every literal -c/-n value from the raw command line (including overridden ones) in uucore, then validate each one in head and tail. Obsolete numeric syntax is left to the existing parser. Added regression tests for both commands.

Closes #15997

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Note: The gnu test tests/df/skip-rootfs was skipped on 'main' but is now failing.

@Logic769
Logic769 force-pushed the head-tail-validate-overridden-counts branch 3 times, most recently from 0b67b2d to 6dc0c1b Compare October 30, 2026 22:02
@codspeed

codspeed Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 55.27%

2 warnings, 1 note

⚠️ 129 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 412 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory socket_addrs_direct[100000] 8.6 KB 68 KB -87.29%
❌ Memory hostname_ip_lookup[100000] 100.9 KB 160.3 KB -37.06%
⚡ Memory cp_recursive_deep_tree[(120, 4)] 789 KB 705.4 KB +11.86%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Logic769:head-tail-validate-overridden-counts (07db268) with main (9ed1dfc)

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@Logic769
Logic769 force-pushed the head-tail-validate-overridden-counts branch from 6dc0c1b to 8875a3f Compare November 3, 2026 15:42
@sylvestre
sylvestre force-pushed the head-tail-validate-overridden-counts branch from 8f7d652 to c3bb223 Compare November 6, 2026 11:07
Comment thread src/uu/tail/src/args.rs Resolved
Comment thread src/uu/tail/src/args.rs Resolved
Comment thread src/uu/tail/src/args.rs Resolved
Comment thread src/uu/head/src/head.rs Resolved
Comment thread tests/by-util/test_head.rs Resolved
@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the work on this!
The argv scan misses abbreviated long options (--byte=1-3) and copies the existing error code; details inline.
Please move the sign-only message change to its own PR and squash the rest into one commit.
CodSpeed shows a 3.89% slowdown, so please check where it comes from.

@Logic769
Logic769 force-pushed the head-tail-validate-overridden-counts branch 2 times, most recently from bc60cf3 to d5241e1 Compare November 18, 2026 04:37
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.50 MB (+112 KB, +0.07%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@Logic769

Copy link
Copy Markdown
Contributor Author

CI failure analysis: Build (ubuntu-latest, x86_64-unknown-linux-gnu, feat_os_unix,test_risky_names, use-cross, true) failed only in test_pr::test_missing_non_utf8_input_does_not_read_stdin with failed to write to stdin of child: Broken pipe (os error 32) at tests/uutests/src/lib/util.rs:2982 (6917 passed, 1 failed). This is a stdio race in the test harness: coreutils pr exits before the harness has finished writing the non-UTF-8 input to its stdin. It is unrelated to this PR's head/tail changes, and rerunning the job should clear it.

@Logic769
Logic769 force-pushed the head-tail-validate-overridden-counts branch from 95ef792 to 07db268 Compare November 25, 2026 16:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

head: an invalid -c value is ignored when -n comes later

2 participants