https://bugs.winehq.org/show_bug.cgi?id=37940
Bug ID: 37940 Summary: Invalid file buffering behavior causes data corruption Product: Wine Version: 1.7.34 Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: major Priority: P2 Component: msvcrt Assignee: wine-bugs@winehq.org Reporter: ho-rr-or@mail.ru Distribution: ---
Created attachment 50543 --> https://bugs.winehq.org/attachment.cgi?id=50543 Compiled binary to reproduce
msvcrt file routines sometimes corrupt file data by invalid buffer flushing. Reproduced by following code (compiled binary attached):
char data[68200]; char buf[sizeof(data)]; for (int i = 0; i < sizeof(data); i++) data[i] = rand();
FILE* f = _wfsopen(L"test.bin", L"wb+", 64);
rewind(f); fwrite(data, 1, 68100, f);
// Following calls possible corrupt buffer rewind(f); fread(buf, 1, 40000, f); fread(buf, 1, 40000, f);
// Following call causes wrong buffer flushing fwrite(&data[68100], 1, 100, f);
fclose(f);
f = fopen("test.bin", "rb"); fread(buf, 1, sizeof(buf), f); fclose(f); printf("Memcmp: %d\n", memcmp(data, buf, sizeof(buf)));
Windows output: Memcmp: 0
Wine output: Memcmp: -1
Windows file size: 68200 Wine file size: 72296
Bug causes at least cl.exe in Microsoft Visual Studio 2008/2010. Reproduced when cl.exe generates precompiled header.
test.h: #pragma once #include "Windows.h" #include <iostream>
test.cpp: #include "test.h"
int main() { std::cout << "WORKS!" << std::endl; return 0; }
Command to reproduce: rm test.pch; wine cl.exe /Yctest.h test.cpp
https://bugs.winehq.org/show_bug.cgi?id=37940
Mikhail Bystryantsev ho-rr-or@mail.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |ho-rr-or@mail.ru
https://bugs.winehq.org/show_bug.cgi?id=37940
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download, source, testcase
https://bugs.winehq.org/show_bug.cgi?id=37940
Piotr Caban piotr.caban@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |piotr.caban@gmail.com
--- Comment #1 from Piotr Caban piotr.caban@gmail.com --- The attached test works now (commit ba0d1586ff53221e449f2ed885a059232dd4bea8). Please retest.
https://bugs.winehq.org/show_bug.cgi?id=37940
--- Comment #2 from Mikhail Bystryantsev ho-rr-or@mail.ru --- Attached test now works fine, but the cl.exe still does not. I'll try to check that it is still due to this bug and provide more test cases.
https://bugs.winehq.org/show_bug.cgi?id=37940
--- Comment #3 from Mikhail Bystryantsev ho-rr-or@mail.ru --- Created attachment 50553 --> https://bugs.winehq.org/attachment.cgi?id=50553 Second binary for reproduce
There is new binary for reproduce. I reproduced a nearly the same operations that performs cl.exe.
char data[68100 + 65536]; char buf[sizeof(data)]; for (int i = 0; i < sizeof(data); i++) data[i] = rand();
FILE* f = _wfsopen(L"test.bin", L"wb+", 64);
rewind(f); fwrite(data, 1, 68100, f);
// Following calls possible corrupt buffer rewind(f); fread(buf, 1, 32512, f); fread(buf, 1, 4096, f); fread(buf, 1, 28672, f); fread(buf, 1, 4096, f); fread(buf, 1, 29948, f);
// Following call causes wrong buffer flushing fwrite(&data[68100], 1, 65536, f);
fclose(f);
f = fopen("test.bin", "rb"); fread(buf, 1, sizeof(buf), f); fclose(f); printf("Memcmp: %d\n", memcmp(data, buf, sizeof(buf)));
https://bugs.winehq.org/show_bug.cgi?id=37940
--- Comment #4 from Piotr Caban piotr.caban@gmail.com --- The attached test is working again. Could you please give it a try? (commit 90b68f99648a0a0be73673fd99e140e18bfb5c35)
https://bugs.winehq.org/show_bug.cgi?id=37940
--- Comment #5 from Mikhail Bystryantsev ho-rr-or@mail.ru --- Now cl.exe works fine. Nice work!
https://bugs.winehq.org/show_bug.cgi?id=37940
Piotr Caban piotr.caban@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Fixed by SHA1| |90b68f99648a0a0be73673fd99e | |140e18bfb5c35 Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED
--- Comment #6 from Piotr Caban piotr.caban@gmail.com --- Marking as fixed.
https://bugs.winehq.org/show_bug.cgi?id=37940
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #7 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 1.7.36.