Pipes truncating data in cygwin from main and cygwin-3_4-branch
Mon Aug 14 11:51:39 GMT 2023
I have a problem that looks like pipes are truncating data when I cat a file to my program’s stdin. A simple `cat foo | cat > bar` works fine. bar ends up identical to foo. It is more complicated than that. My application is doing this
buffer << std::cin.rdbuf();
std::istream* isp = &buffer;
Initial reads after this work fine. Once the app has read everything up to the payload data in the file, it does
off_t dataStart = (off_t)(isp->tellg());
off_t dataEnd = (off_t)(isp->tellg());
dataSizeInFile = dataEnd - dataStart;
The tellg result shows the size is significantly less than the actual file data. 43k less in a 170k file. It is seemingly being truncated somewhere.
Later the app does
std::streambuf* _streambuf = (isp->rdbuf());
and starts reading from _streambuf. All data read from _streambuf is gibberish.
The application code makes no distinction between a pipe and stdin redirection from a file. It just uses std::cin. stdin redirection still works.
I created a minimal reproducer. More on that in a moment.
I first encountered this in Git for Windows 2.41.0. I had no problem in previous versions. I reported this to the Git for Windows project. See https://github.com/git-for-windows/git/issues/4464. You can find the minimal reproducer over there. It consists of 2 parts, a script and a small c++ program. The script finds the size of the target file then cats it to the test program passing the file size as a command line option. The test program does what I have described above and compares the file size determined from the seek to the end with the provided size.
A G4W project member reports that the problem reproduces on vanilla Cygwin in the branches mentioned in the subject and that G4W and MSYS2 are on the cygwin-3_4-branch release train. He recommends reporting the bug to you, You can find his(?) full comment here <https://github.com/git-for-windows/git/issues/4464#issuecomment-1671137446>.
I am not using cygwin directly so I can’t provide the output from `cygcheck`.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 528 bytes
Desc: Message signed with OpenPGP
More information about the Cygwin