View Issue Details

IDProjectCategoryView StatusLast Update
0000500Far ManagerCopy/Movepublic2008-03-24 04:58
ReporteralexmitinAssigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000500: FAR Copy overwrites files without any prompt
DescriptionProblem
----------------
During file copying FAR overwrites existing files without any prompt.


Steps to reproduce:
----------------------
1. Create a folder C:\222

2. Right mouse click on the C:\222 folder and select "Properties".

3. Go to "Security" tab. Press "Advanced" button.

4. Assign the following rights to the C:\222 folder:

  Administrators: Full Control
  Users: Create Files/Write Data

5. Start FAR under limited user account (not administrator) without any plugins.

6. Do not go to C:\222 folder in a FAR Manager.

7. Create a text file C:\111\myfile.txt.

8. Using FAR select file C:\111\myfile.txt, press F5, type C:\222 as a destination in the copy dialog, press "Copy" button.

The file will be copied successfully.

9. Press Shift+F4, then type C:\222\myfile.txt, press OK.

The file will be loaded in the editor. Change the file content and save it.

10. Using FAR Manager select the file C:\111\myfile.txt again, press F5 and type C:\222 in the copy dialog, press "Copy" button.

The file is copied successfully overwriting the existing file without any prompt.


Analysis
====================
The problem occurs in the following code:

COPY_CODES ShellCopy::ShellCopyOneFile(
  const wchar_t *Src,
  const FAR_FIND_DATA_EX &SrcData,
  const wchar_t *Dest,
  int KeepPathPos,
  int Rename
)
{
...
  if ((FindHandle=apiFindFirstFile(strDestPath,&DestData))==INVALID_HANDLE_VALUE)
  {
     DestAttr=(DWORD)-1; ==[code.A]==
  }
  else
  {
     FindClose(FindHandle);
     DestAttr=DestData.dwFileAttributes;
  }
...
  if (DestAttr!=(DWORD)-1 && (DestAttr & FILE_ATTRIBUTE_DIRECTORY)==0) ==[code.B]==
  {
    if(!RenameToShortName)
    {
      if (SrcData.nFileSize==DestData.nFileSize)
      {
...
      }

      int RetCode;
      if (!AskOverwrite(SrcData,strDestPath,DestAttr,SameName,Rename,((ShellCopy::Flags&FCOPY_LINK)?0:1),Append,RetCode))
      {
        return((COPY_CODES)RetCode);
      }
...
}

Because the directory listing is disable for the limited user (see step 4 above) the apiFindFirstFile() function returns INVALID_HANDLE_VALUE. DestAttr is assigned -1 (code.A).

The condition in code.B will be FALSE. Thus the AskOverwrite() function will not be called.


The proposed fix
==================
1) The code.A should be modifed so in case if FindHandle==INVALID_HANDLE_VALUE the additional check for the destination file existence should be made. This can be done by opening the file handle, determining the file size (used later in a code) and closing the file handle.

2) The function ShellCopy::AskOverwrite() should be modified to handle the case when the directory listing is disabled.

Additional InformationFAR 1.80.0.452 without plugins
Options/Confirmations: [x] Copy

Copy dialog parameters:

Copy to: C:\222
Access rights: Default

[ ] Only newer files
[ ] Copy contents of symbolic links
[ ] Process multiple destinations
[ ] Use filter

TagsNo tags attached.
Build

Activities

ujos

2008-03-23 03:25

reporter   bugnote:0001407

Step "9. Press Shift+F4, then type C:\222\myfile.txt, press OK." cannot be reproduced, because limited user cannot read data from file.

alexmitin

2008-03-23 14:13

reporter   bugnote:0001411

Correction.

Steps to reproduce:
----------------------
1. Create a folder C:\222 using administrator account (the owner of this folder should be "Administrator" account or "Administrators" group).

2. Right mouse click on the C:\222 folder and select "Properties".

3. Go to "Security" tab. Press "Advanced" button.

4. Assign the following rights to the C:\222 folder:

  Administrators: Full Control (This folder, subfolders and files)
  Users: Create Files/Write Data (This folder and subfolders)
  CREATOR OWNER: Full Control (Subfolders and files only)

5. Start FAR under limited user account (not administrator) without any plugins.

6. Do not go to C:\222 folder in a FAR Manager.

7. Create a text file C:\111\myfile.txt.

8. Using FAR select file C:\111\myfile.txt, press F5, type C:\222 as a destination in the copy dialog, press "Copy" button.

The file will be copied successfully. The owner of this files is limited user account.

9. Press Shift+F4, then type C:\222\myfile.txt, press OK.

The file will be loaded in the editor. Change the file content and save it.

10. Using FAR Manager select the file C:\111\myfile.txt again, press F5 and type C:\222 in the copy dialog, press "Copy" button.

11. Press Shift+F4, then type C:\222\myfile.txt, press OK to load the destination file content.


The file was copied successfully overwriting the existing file without any prompt.



The problem occurs only in FAR 1.80, it does not occur in FAR 1.71 (build 2335).

alexmitin

2008-03-23 14:35

reporter   bugnote:0001412

Actually the problem occurs in FAR 1.71 (build 2335) too.

ujos

2008-03-24 04:58

reporter   bugnote:0001416

IMHO FAR should not try to find file at all. It should try open file for wrinting. If success, it should display overwrite dialog. If "OK", it should continue copying.

Issue History

Date Modified Username Field Change
2008-03-19 06:05 alexmitin New Issue
2008-03-23 03:25 ujos Note Added: 0001407
2008-03-23 14:13 alexmitin Note Added: 0001411
2008-03-23 14:35 alexmitin Note Added: 0001412
2008-03-24 04:58 ujos Note Added: 0001416