Skip to content

Preserve binary data when copying file streams - #22

Merged
troglobit merged 1 commit into
troglobit:masterfrom
omrzk:fix/copy-binary-file-streams
Nov 14, 2026
Merged

troglobit merged 1 commit into
troglobit:masterfrom
omrzk:fix/copy-binary-file-streams

Conversation

@omrzk

@omrzk omrzk commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

fcopyfile() currently uses fgets() and fputs(), so an embedded NUL silently drops the rest of that input chunk. Read and write failures also return success.

Copy counted bytes with fread()/fwrite() and return an error for failed transfers, while preserving the caller's stream positions and ownership. Add binary boundary/offset tests, nonblocking-pipe read errors, an unbuffered /dev/full write error, and the existing NULL-argument contract.

Validation: the exact new regression fails on current master and passes with this change; GCC 13 build, focused tests, and ASan/UBSan/LeakSanitizer pass. Full make check passes 21 of 22 tests; the unchanged pidfile test fails because this environment cannot write /var/tmp, reproduced on clean master. make distcheck includes and passes the new test, then hits the same existing pidfile restriction. Native Clang, Debian packaging and other operating systems were not tested locally. Buffered flush errors remain the caller's responsibility.

Copy the bytes returned by fread instead of treating each input chunk as a NUL-terminated string. Preserve the public stream positions and report read and write failures rather than returning success after a partial copy. Add binary boundary, current-position, native pipe error and full-device regression coverage.

@troglobit troglobit left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ah, nice catch, thank you! 🙏

@troglobit
troglobit merged commit dff88a6 into troglobit:master Nov 14, 2026
3 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.

2 participants