View Issue Details

IDProjectCategoryView StatusLast Update
0034441FPCPackagespublic2018-10-25 07:47
ReporterOndrej PokornyAssigned ToMarco van de Voort 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformwin32OSWindows 10OS Version
Product Version3.3.1Product Build39975 
Target VersionFixed in Version3.3.1 
Summary0034441: _SHFILEOPSTRUCTW is wrongly packed (has wrong structure)
Description_SHFILEOPSTRUCTW has wrong structure. As a result fAnyOperationsAborted and hNameMappings cannot be read after a SHFileOperationW call.
Steps To ReproduceSee the attached project. Run it. See the (1) and (2) marked lines in the source:

(1) Assertion fails: fAnyOperationsAborted receives an arbitrary number.
(2) hNameMappings receives an invalid pointer.

If I declare _SHFILEOPSTRUCTW as a packed record (uncomment the section) the bug disappears.
Additional Information_SHFILEOPSTRUCTA is affected as well.
TagsNo tags attached.
Fixed in Revision40020,40024
FPCOldBugId
FPCTarget
Attached Files
  • SHFILEOPSTRUCTW.zip (1,457 bytes)
  • shellapi-packrecords.patch (358 bytes)
    Index: packages/winunits-base/src/shellapi.pp
    ===================================================================
    --- packages/winunits-base/src/shellapi.pp	(revision 39975)
    +++ packages/winunits-base/src/shellapi.pp	(working copy)
    @@ -18,7 +18,7 @@
     {$smartlink on}
     {$endif}
     
    -{$PACKRECORDS C}
    +{$PACKRECORDS 1}
     {$calling stdcall}
     {$mode objfpc}
     
    
  • shellapi-packrecords-02.patch (416 bytes)
    Index: packages/winunits-base/src/shellapi.pp
    ===================================================================
    --- packages/winunits-base/src/shellapi.pp	(revision 39975)
    +++ packages/winunits-base/src/shellapi.pp	(working copy)
    @@ -18,7 +18,11 @@
     {$smartlink on}
     {$endif}
     
    -{$PACKRECORDS C}
    +{$ifdef WIN64}
    +  {$PACKRECORDS C}
    +{$else}
    +  {$PACKRECORDS 1}
    +{$endif}
     {$calling stdcall}
     {$mode objfpc}
     
    

Activities

Ondrej Pokorny

2018-10-19 21:34

developer  

SHFILEOPSTRUCTW.zip (1,457 bytes)

Ondrej Pokorny

2018-10-19 22:00

developer  

shellapi-packrecords.patch (358 bytes)
Index: packages/winunits-base/src/shellapi.pp
===================================================================
--- packages/winunits-base/src/shellapi.pp	(revision 39975)
+++ packages/winunits-base/src/shellapi.pp	(working copy)
@@ -18,7 +18,7 @@
 {$smartlink on}
 {$endif}
 
-{$PACKRECORDS C}
+{$PACKRECORDS 1}
 {$calling stdcall}
 {$mode objfpc}
 

Ondrej Pokorny

2018-10-19 22:01

developer   ~0111477

Last edited: 2018-10-19 22:01

View 2 revisions

Possible patch attached. Please test somebody with the win64 target. I sucessfully tested it with win32.

Serge Anvarov

2018-10-20 16:17

reporter   ~0111488

Did you tested on Win64? As I see ShellAPI.h contains:
#if !defined(_WIN64)
#include <pshpack1.h>
#endif
...
#if !defined(_WIN64)
#include <poppack.h>
#endif
That is, all structures must be packed, but only for Win32

Ondrej Pokorny

2018-10-21 08:23

developer   ~0111494

> Did you tested on Win64?

No, if you read my first note, you see that I kindly ask somebody to test win64.

> As I see ShellAPI.h contains

Very good, that means we need an {$IFNDEF WIN64}.

Serge Anvarov

2018-10-21 16:29

reporter   ~0111497

Last edited: 2018-10-21 16:31

View 2 revisions

I tested on Win7 x64.
The good news is no patch is required. Works correctly without packed and with packed incorrectly (get internal error, when uncomment).

Detail: with operation FO_MOVE flag FOF_NOCONFIRMATION suggests the answer is "Yes to all" and for move this means to replace, not save with new name. As a result, hNameMappings is nil because there is no new name.
With operation FO_COPY flag FOF_NOCONFIRMATION make new name.

I don't know how to force a function to make new names when FO_MOVE and FOF_NOCONFIRMATION. Without FOF_NOCONFIRMATION in dialog you can select new name and hNameMappings become valid.
The behavior is the same for 32-bit or 64-bit applications.

Ondrej Pokorny

2018-10-22 14:34

developer  

shellapi-packrecords-02.patch (416 bytes)
Index: packages/winunits-base/src/shellapi.pp
===================================================================
--- packages/winunits-base/src/shellapi.pp	(revision 39975)
+++ packages/winunits-base/src/shellapi.pp	(working copy)
@@ -18,7 +18,11 @@
 {$smartlink on}
 {$endif}
 
-{$PACKRECORDS C}
+{$ifdef WIN64}
+  {$PACKRECORDS C}
+{$else}
+  {$PACKRECORDS 1}
+{$endif}
 {$calling stdcall}
 {$mode objfpc}
 

Ondrej Pokorny

2018-10-22 14:46

developer   ~0111512

OK, thanks for the information.

I updated another patch with ifdef win64.

Marco van de Voort

2018-10-24 17:05

manager   ~0111537

Committed.

Ondrej Pokorny

2018-10-24 17:14

developer   ~0111538

Thank you!

Ondrej Pokorny

2018-10-24 17:16

developer   ~0111540

You forgot the "{" in $endif}.

Issue History

Date Modified Username Field Change
2018-10-19 21:34 Ondrej Pokorny New Issue
2018-10-19 21:34 Ondrej Pokorny File Added: SHFILEOPSTRUCTW.zip
2018-10-19 22:00 Ondrej Pokorny File Added: shellapi-packrecords.patch
2018-10-19 22:01 Ondrej Pokorny Note Added: 0111477
2018-10-19 22:01 Ondrej Pokorny Note Edited: 0111477 View Revisions
2018-10-20 16:17 Serge Anvarov Note Added: 0111488
2018-10-21 08:23 Ondrej Pokorny Note Added: 0111494
2018-10-21 16:29 Serge Anvarov Note Added: 0111497
2018-10-21 16:31 Serge Anvarov Note Edited: 0111497 View Revisions
2018-10-22 14:34 Ondrej Pokorny File Added: shellapi-packrecords-02.patch
2018-10-22 14:46 Ondrej Pokorny Note Added: 0111512
2018-10-24 17:05 Marco van de Voort Fixed in Revision => 40020
2018-10-24 17:05 Marco van de Voort Note Added: 0111537
2018-10-24 17:05 Marco van de Voort Status new => resolved
2018-10-24 17:05 Marco van de Voort Fixed in Version => 3.3.1
2018-10-24 17:05 Marco van de Voort Resolution open => fixed
2018-10-24 17:05 Marco van de Voort Assigned To => Marco van de Voort
2018-10-24 17:14 Ondrej Pokorny Note Added: 0111538
2018-10-24 17:14 Ondrej Pokorny Status resolved => closed
2018-10-24 17:16 Ondrej Pokorny Note Added: 0111540
2018-10-24 17:16 Ondrej Pokorny Status closed => feedback
2018-10-24 17:16 Ondrej Pokorny Resolution fixed => reopened
2018-10-24 22:59 Marco van de Voort Fixed in Revision 40020 => 40020,40024
2018-10-24 22:59 Marco van de Voort Status feedback => resolved
2018-10-24 22:59 Marco van de Voort Resolution reopened => fixed
2018-10-25 07:47 Ondrej Pokorny Status resolved => closed