https://bugs.winehq.org/show_bug.cgi?id=56837
Bug ID: 56837 Summary: Bad file pointer after a file write in appending mode Product: Wine Version: unspecified Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: -unknown Assignee: wine-bugs@winehq.org Reporter: sldev@free.fr Distribution: Other
Created attachment 76648 --> https://bugs.winehq.org/attachment.cgi?id=76648 bug-demo program and its source file
When writing for append into a file, Wine returns a bad ftell() file pointer unless a fflush() is performed before querying with ftell().
See the bug-demo program (run it under bare metal Windows, then under Wine).
This bug has existed like forever (Wine 6 and newer, for sure).
https://bugs.winehq.org/show_bug.cgi?id=56837
Fabian Maurer dark.shadow4@web.de changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |dark.shadow4@web.de
https://bugs.winehq.org/show_bug.cgi?id=56837
reserv0@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |reserv0@yahoo.com
--- Comment #1 from reserv0@yahoo.com --- *BUMP*
Is anyone looking into this?
This bug causes cache files corruptions with some applications and is pretty serious, since it breaks a very basic underlying standard C library call.
https://bugs.winehq.org/show_bug.cgi?id=56837
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Version|unspecified |6.0 Keywords| |download, source
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #2 from Dmitry Timoshkov dmitry@baikal.ru --- Created attachment 78272 --> https://bugs.winehq.org/attachment.cgi?id=78272 patch
This patch makes the attached test work in Wine.
https://bugs.winehq.org/show_bug.cgi?id=56837
Dmitry Timoshkov dmitry@baikal.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |piotr.caban@gmail.com
--- Comment #3 from Dmitry Timoshkov dmitry@baikal.ru --- Adding Piotr, probably he has an opinion on this.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #4 from Dmitry Timoshkov dmitry@baikal.ru --- Created attachment 78273 --> https://bugs.winehq.org/attachment.cgi?id=78273 Modified test with more traces
Modified test adds traces to compare FILE and fd backend behaviour.
https://bugs.winehq.org/show_bug.cgi?id=56837
Dmitry Timoshkov dmitry@baikal.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1
--- Comment #5 from Dmitry Timoshkov dmitry@baikal.ru --- Confirming.
https://bugs.winehq.org/show_bug.cgi?id=56837
Dmitry Timoshkov dmitry@baikal.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #78272|0 |1 is obsolete| |
--- Comment #6 from Dmitry Timoshkov dmitry@baikal.ru --- Created attachment 78274 --> https://bugs.winehq.org/attachment.cgi?id=78274 patch
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #7 from sldev sldev@free.fr --- Yup, the proposed patch does fix the issue, thank you ! :-)
https://bugs.winehq.org/show_bug.cgi?id=56837
Piotr Caban piotr.caban@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Component|-unknown |msvcrt
--- Comment #8 from Piotr Caban piotr.caban@gmail.com --- I have created MR that should fix the bug: https://gitlab.winehq.org/wine/wine/-/merge_requests/7651
It's based on Dmitry's patch but moves seek to _flsbuf function.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #9 from sldev sldev@free.fr --- (In reply to Piotr Caban from comment #8)
I have created MR that should fix the bug: https://gitlab.winehq.org/wine/wine/-/merge_requests/7651
It's based on Dmitry's patch but moves seek to _flsbuf function.
Err, no, this is not a correct fix for the issue at hand. The problem was that the write happened at the start of the file instead of at the end, while the file was opened in append mode (with no lseek() call used at all: see the bug-demo sources).
The suggested patch ( https://bugs.winehq.org/attachment.cgi?id=78274 ) is exactly what we need and what restores the normal behaviour of fwrite() in append mode.
Instead, https://gitlab.winehq.org/wine/wine/-/merge_requests/7651 addresses only an issue with _lseek(), which won't fix our issue.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #10 from Piotr Caban piotr.caban@gmail.com --- I don't understand what's wrong, could you please describe it in more detail? I have verified that both test application output and file content is the same as on Windows.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #11 from Dmitry Timoshkov dmitry@baikal.ru --- (In reply to Piotr Caban from comment #10)
I don't understand what's wrong, could you please describe it in more detail? I have verified that both test application output and file content is the same as on Windows.
I can confirm that with the proposed MR 7651 attached test shows same result under Wine as observed under Windows.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #12 from sldev sldev@free.fr --- (In reply to Piotr Caban from comment #10)
I don't understand what's wrong, could you please describe it in more detail? I have verified that both test application output and file content is the same as on Windows.
(In reply to Dmitry Timoshkov from comment #11)
(In reply to Piotr Caban from comment #10)
I don't understand what's wrong, could you please describe it in more detail? I have verified that both test application output and file content is the same as on Windows.
I can confirm that with the proposed MR 7651 attached test shows same result under Wine as observed under Windows.
Hmm... Maybe, *if* _flsbuf() is *systematically* called during fwrite() ?... I must admit I did not look at the surrounding code and I'm not familiar with Wine at a source code level... But the first patch looked "safer" to me, since the file pointer was set just before the actual write to the file.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #13 from Piotr Caban piotr.caban@gmail.com --- The actual write to the file happens in _write function (not in fwrite). _write calls _lseek before writing to the file. So we're only trying to fix value returned by ftell/tell. The position where data is written to the file is not changed by any of these patches.
It's possible to find where seek is happening. I have written some tests to confirm it should not happen in every call to fwrite. I didn't add them to the patch because I don't think it shows anything useful - I have added flsbuf() tests instead.
https://bugs.winehq.org/show_bug.cgi?id=56837
Dmitry Timoshkov dmitry@baikal.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Fixed by SHA1| |a165fd43dc4c115d9e9ca0cc817 | |39045ea5f5fe5 Resolution|--- |FIXED
--- Comment #14 from Dmitry Timoshkov dmitry@baikal.ru --- This should be fixed by a165fd43dc4c115d9e9ca0cc81739045ea5f5fe5.
If the problem persists please feel free to reopen.
https://bugs.winehq.org/show_bug.cgi?id=56837
--- Comment #15 from sldev sldev@free.fr --- I just made a build (of Wine 10.2, because 10.3+ makes CEF crash, and I need the latter) with a165fd43dc4c115d9e9ca0cc81739045ea5f5fe5 applied, and I can confirm that this issue is fixed for the program I was seeing it happening with (and for the bug-demo program).
Thank you ! :-)