Serious Data corruption bug in "Compare by content"

Please report only one bug per message!

Moderators: sheep, Hacker, Stefan2, white

User avatar
milo1012
Power Member
Power Member
Posts: 1100
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 » 2012-02-05, 19:51 UTC

umbra wrote:So it's no wonder it emulates Notepad as much as possible. :)
Of course it is...but the exact behavior of Windows Notepad in terms of file handling is not documented and can only be observed.
What I mean is that every Program approaches that different...programming file handling in MFC in Visual Studio is completely different than in .Net, JAVA or things like MinGW.
So propably, if you don't follow file handling recommendations from Microsoft or it's just your goal to be able to do it anyway then you end up like this: we have a lot of programs that allow writing locked files and many that don't.

User avatar
MVV
Power Member
Power Member
Posts: 8383
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2012-02-06, 05:38 UTC

Well, I've tested it with WordPad, it doesn't allow to save file. Maybe it checks it somehow.

It is strange but I can't save a file using standard Notepad if it was opened by following sample code:

Code: Select all

	HANDLE hfile=CreateFile(L"D:\\testfile.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
	HANDLE hmap=CreateFileMapping(hfile, 0, PAGE_READWRITE, 0, 0, 0);

	MessageBox(0, L"1", L"2", 0);
	CloseHandle(hmap);
	CloseHandle(hfile);
BTW, it works correctly even with FILE_SHARE_READ|FILE_SHARE_WRITE sharing flags! Notepad is unable to save file until I click a button in a message box.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38017
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2012-02-06, 16:36 UTC

I'm opening the file with GENERIC_READ access and sharing flags set to
FILE_SHARE_READ | FILE_SHARE_WRITE. This is done so I can also compare files which are currently open in some other program. If I used only FILE_SHARE_READ, I couldn't open e.g. active database files.
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8383
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2012-02-06, 19:48 UTC

Maybe you should try to open with just FILE_SHARE_READ at first? You can then open with both FILE_SHARE_READ|FILE_SHARE_WRITE on fail - in such case you may disable 'edit' button or show a message to user. Anyway you can't edit binary files.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38017
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2012-02-09, 15:25 UTC

Your sugestion to try with FILE_SHARE_READ first is good. Btw, the problem isn't about editing the file with TC, but with an external editor.
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8383
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2012-02-09, 16:08 UTC

Problem is that external editor is able to open end edit file while it is mapped. We see that many editors can't check if file is mapped, so we should try to prevent them from modifying a file.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38017
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2012-02-10, 11:31 UTC

OK, try beta 19.
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8383
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2012-02-10, 12:06 UTC

Nice, file is locked while it is being compared in b19.

umbra
Power Member
Power Member
Posts: 807
Joined: 2012-01-14, 20:41 UTC

Post by *umbra » 2012-02-10, 12:51 UTC

In beta 19, if some file is larger than 1 MiB it's locked.

However the help says:
Files up to 2 MB will be loaded completely into memory, so the originals will remain editable. Larger files will only be mapped to memory, i.e. they remain locked during the comparison.
Are those 2 MiB a typo or I'm missing something?
Windows 7 Pro x64, Windows 10 Pro x64

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38017
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2012-02-10, 13:25 UTC

It's badly explained, the 2 MB is the memory it may take when both files are loaded into memory.
Author of Total Commander
http://www.ghisler.com

Post Reply