Skip to content

cat: bugfix when running with -T option #7636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

karlmcdowall
Copy link
Contributor

@karlmcdowall karlmcdowall commented Apr 2, 2025

Fixes #7637
Fixes an crash seen when running with -T option if no newline is found in a buffer.
Added unit test to validate.

@@ -644,7 +644,7 @@ fn write_tab_to_end<W: Write>(mut in_buf: &[u8], writer: &mut W) -> usize {
}
None => {
writer.write_all(in_buf).unwrap();
return in_buf.len();
return in_buf.len() + count;
Copy link
Contributor Author

@karlmcdowall karlmcdowall Apr 2, 2025

Choose a reason for hiding this comment

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

Line 638 above moves the in_buf slice along the original input in_buf. If the function later returns because no \r or \n characters were found (i.e. we match to line 645) then we would return just the size of the final slice, when in fact we should be returning the size of the entire buffer.

@karlmcdowall karlmcdowall force-pushed the cat_find_a_bug_fix_a_bug branch from 6d75472 to cb3ac65 Compare April 2, 2025 23:05
Copy link

github-actions bot commented Apr 2, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

Fixes an crash seen when running with -T option if no newline
is found in a buffer.
Added unit test to validate.
Copy link

github-actions bot commented Apr 3, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@cakebaker cakebaker merged commit 7af2c94 into uutils:main Apr 3, 2025
68 checks passed
@cakebaker
Copy link
Contributor

Thanks!

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.

cat: panic when running with -T
2 participants