[Bug 40200] New: ftell function problems
https://bugs.winehq.org/show_bug.cgi?id=40200 Bug ID: 40200 Summary: ftell function problems Product: Wine Version: unspecified Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: -unknown Assignee: wine-bugs(a)winehq.org Reporter: eliidida(a)gmail.com Distribution: --- Hello, I have a console application for Windows so it's a .exe. The console .exe only has one function, no GUI or anything. The console application basically obfuscates a file. Command: ConsoleApp.exe FileName.dylib I have tried Wine (stable or development builds) and while I can run the console application fine, and it exits with "Success", the problem is the output file that is ran using Wine on Linux has a slight difference compared to the output file that was ran using the same .exe but on Windows. After investigating the console .exe program, we found out that the whole problem was due to a piece of code in the .exe "ftell function". Wine apparently doesn't support it? Or something similar because if we compare the two output files, the only difference is in here: http://i.imgur.com/vghTN2X.png Left is Wine on Linux (Ubuntu) and Right is normal Windows OS output file. This is the ftell code: https://imgur.com/UrkJ36V Can you verify this? I did ask on IRC and on the Forums, they told me to submit a bug report. Thank you for your time and I hope a fix for this comes as soon as possible so I can bring my project to life. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=40200 --- Comment #1 from eliidida(a)gmail.com --- Here is my example .exe and my example .dylib file. https://www.dropbox.com/s/002qu6hoqfn7nxg/CPLoaderConsole.zip?dl=0 Usage: CPLoaderConsole.exe example.dylib The file size of the .dylib should raise by a few KB. Then, compare the output .dylibs from Windows and Wine on Linux using Beyond Compare 4 (or any other tools) and see the difference. Thank you! -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
https://bugs.winehq.org/show_bug.cgi?id=40200 eliidida(a)gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Alias| |Anthony -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 Janne <janne.kekkonen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |janne.kekkonen@gmail.com --- Comment #2 from Janne <janne.kekkonen@gmail.com> --- Hello, Seems that these links do not work anymore: https://imgur.com/UrkJ36V https://www.dropbox.com/s/002qu6hoqfn7nxg/CPLoaderConsole.zip?dl=0 Is this still an issue with current Wine? -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 Janne <janne.kekkonen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC|janne.kekkonen@gmail.com | -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 Ken Sharp <imwellcushtymelike@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Alias|Anthony | Status|UNCONFIRMED |NEEDINFO Keywords| |Abandoned? -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 --- Comment #3 from Anthony <eliidida@gmail.com> --- Hi Janne, Thank you for getting back to this! We ended up porting the program to Linux natively so if possible, please delete this bug entirely. Thank you! -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 --- Comment #4 from Nikolay Sivov <bunglehead@gmail.com> --- (In reply to Anthony from comment #3)
Hi Janne,
Thank you for getting back to this! We ended up porting the program to Linux natively so if possible, please delete this bug entirely.
Thank you!
If there is an actual issue in Wine implementation, we would be interested in learning about it, regardless of your porting approach. Do you recall what was the issue, and how to reproduce it? -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 Rodrigo Batista de Moraes <rodrigobatsmoraes@hotmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rodrigobatsmoraes@hotmail.c | |om --- Comment #5 from Rodrigo Batista de Moraes <rodrigobatsmoraes@hotmail.com> --- I ran into a problem with `ftell()` when using unbuffered streams in `msvcrt.dll` under Wine. I don't know whether this is what the original reporter encountered, but below is the problem I found, along with a test program that reproduces it. I can create another bug report for it if anyone prefers that. I found this bug while trying to get a Windows build of libfst (GTKWave's FST waveform format parser) to run under Wine. The diagnostics and reproduction below were found by an agentic AI. On a stream made unbuffered with `setvbuf(f, NULL, _IONBF, 0)`, after an `fgetc()`, the stream position reported by `ftell()`, `_ftelli64()` and `fgetpos()` is one byte too far. The position used by `fseek(..., SEEK_CUR)` is off in the same way, so `fseek(f, 0, SEEK_CUR)` followed by `fgetc()` skips a byte. With the default buffering (no `setvbuf()` call), all of them are correct. Seen with wine-11.18 (Arch Linux package), in a new 64-bit prefix, with a program linked against `msvcrt.dll`. Test program, `ftell_ionbf.c`: ```c #include <stdio.h> int main(void) { FILE *f; #ifdef _WIN32 fpos_t pos; #endif int i, c; f = fopen("ftell_ionbf.bin", "wb"); for (i = 0; i < 64; i++) fputc(i, f); fclose(f); f = fopen("ftell_ionbf.bin", "rb"); setvbuf(f, NULL, _IONBF, 0); fseek(f, 32, SEEK_SET); c = fgetc(f); printf("fgetc returned %d\n", c); printf("ftell = %ld\n", ftell(f)); #ifdef _WIN32 /* fpos_t is a plain integer on Windows but a struct in glibc */ fgetpos(f, &pos); printf("_ftelli64 = %lld\n", (long long)_ftelli64(f)); printf("fgetpos = %lld\n", (long long)pos); #endif fseek(f, 0, SEEK_CUR); c = fgetc(f); printf("fgetc after fseek(f, 0, SEEK_CUR) = %d\n", c); fclose(f); return 0; } ``` Steps: 1. Build it with a MinGW-w64 cross-compiler that targets `msvcrt.dll`, e.g.: ```sh x86_64-w64-mingw32-gcc -o ftell_ionbf.exe ftell_ionbf.c ``` (I built it with llvm-mingw 20261006, msvcrt variant: `x86_64-w64-mingw32-clang -o ftell_ionbf.exe ftell_ionbf.c`. `objdump -p ftell_ionbf.exe | grep 'DLL Name'` lists `msvcrt.dll` and `KERNEL32.dll`.) 2. Run it in a new prefix, from the directory holding the `.exe` (it writes a 64-byte file, `ftell_ionbf.bin`, into the current directory): ```sh export WINEPREFIX=$(mktemp -d)/prefix wine ftell_ionbf.exe ``` Output under Wine: ```text fgetc returned 32 ftell = 34 _ftelli64 = 34 fgetpos = 34 fgetc after fseek(f, 0, SEEK_CUR) = 34 ``` The same program built natively on Linux: ```text fgetc returned 32 ftell = 33 fgetc after fseek(f, 0, SEEK_CUR) = 33 ``` Removing the `setvbuf()` line gives 33 everywhere under Wine, so the problem is specific to unbuffered streams. It looks as though `fgetc()` on an unbuffered stream reads ahead into the `FILE`'s internal one-character buffer, and the position calculation does not subtract the character remaining in it. I don't have a Windows machine to test this on, but the project where I found this bug has a Windows CI build, and the output there is the same as on Linux. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 Janne <janne.kekkonen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |janne.kekkonen@gmail.com --- Comment #6 from Janne <janne.kekkonen@gmail.com> --- Hello, I compiled 32bit version of the test app with gcc on Windows 11. Command used to compile: gcc -m32 <filename>.c -o ftell_tst_32.exe Here is output of the test application in Windows 11.
systeminfo |grep 'OS Name' OS Name: Microsoft Windows 11 Pro
./ftell_tst_32.exe fgetc returned 32 ftell = 33 _ftelli64 = 33 fgetpos = 33 fgetc after fseek(f, 0, SEEK_CUR) = 33
file ftell_tst_32.exe ftell_tst_32.exe: PE32 executable for MS Windows 4.00 (console), Intel i386, 17 sections
-- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=40200 Janne <janne.kekkonen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC|janne.kekkonen@gmail.com | -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
participants (2)
-
wine-bugs@winehq.org -
WineHQ Bugzilla