Skip to content

ptx: use char counts for before-chunk sizing in get_output_chunks - #12685

Merged
sylvestre merged 1 commit into
uutils:mainfrom
sylvestre:ptx-fix-panic-multibyte-before
Jul 30, 2026
Merged

ptx: use char counts for before-chunk sizing in get_output_chunks#12685
sylvestre merged 1 commit into
uutils:mainfrom
sylvestre:ptx-fix-panic-multibyte-before

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

The max_before_size assert compared against before.len() (byte length) while max_before_size is measured in chars, panicking on multibyte input like 'éé word'. The tail-chunk budget (max_tail_size) had the same byte/char mismatch, shrinking the tail too much and dropping a word that fits. Use char counts in both places, matching the after chunk.

Fixes #10893

@cakebaker

Copy link
Copy Markdown
Contributor

Hm, the linked issue is already fixed. Is this PR still necessary?

@sylvestre

Copy link
Copy Markdown
Contributor Author

It is a follow up

@sylvestre
sylvestre force-pushed the ptx-fix-panic-multibyte-before branch from ced2a38 to 17ead12 Compare June 7, 2026 19:54
Comment thread tests/by-util/test_ptx.rs
.args(&["-w", "20"])
.pipe_in("aé bé KEY cc dd ee ff gg\n")
.succeeds()
.stdout_contains("cc/ aé");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, GNU ptx doesn't contain such an output:

$ printf "aé bé KEY cc dd ee ff gg\n" | ptx -w20
    /� bé   KEY cc/
             aé bé/
       aé   bé KEY/
    /� KEY   cc dd ee/
       /cc   dd ee ff/
    /cc dd   ee ff gg
    /dd ee   ff gg
     ee ff   gg     /dd

Comment thread tests/by-util/test_ptx.rs
}

#[test]
fn test_unicode_in_before_chunk_does_not_panic() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this test. Our output is quite different than the output of GNU ptx and so I don't know if this test will suddenly start to fail when we reach compatibility with GNU ptx.

The max_before_size assert compared against before.len() (byte length)
while max_before_size is measured in chars, panicking on multibyte input
like 'éé word'. The tail-chunk budget (max_tail_size) had the same
byte/char mismatch, shrinking the tail too much and dropping a word that
fits. Use char counts in both places, matching the after chunk.

Fixes uutils#10893
@sylvestre
sylvestre force-pushed the ptx-fix-panic-multibyte-before branch from 17ead12 to 9601c75 Compare July 4, 2026 16:36
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

@sylvestre
sylvestre merged commit 9449873 into uutils:main Jul 30, 2026
177 checks passed
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.

ptx <<< "🎉 34054698701234657890123456789 0" panics

2 participants