rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

PAR::Packer Executable Works via Powershell but not in IIS #41

Closed Andrew-Kulpa closed 3 years ago

Andrew-Kulpa commented 3 years ago

Description

When I run a PAR::Packer compiled CGI script directly from Powershell, it works as expected. But, when I run the same executable from IIS 10.0 (Windows Server 2019) I receive the following error: HTTP Error 502.2 - Bad Gateway The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Usage: \\?\C:\inetpub\wwwroot\parpacker_test.exe [ -Alib.par ] [ -Idir ] [ -Mmodule ] [ src.par ] [ program.pl ] \\?\C:\inetpub\wwwroot\parpacker_test.exe [ -B|-b ] [-Ooutfile] src.par ".

When I run the same script compiled instead using PerlApp in IIS 10.0, the web server responds with the Hello World! response I'm expecting.

Detailed Description

When running the PAR::Packer compiled script from IIS, the script is running from the IUSR user. Only one of the par-XXX cache directories is created with only 4 dlls and a parpacker_test.exe. The same user is able to run the same script using an executable created using PerlApp. I've included the test script, the non-working directory contents, and the working directory contents below.

Test Script

#!/usr/bin/perl

print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello</title>';
print '</head>';
print '<body>';
print '<h2>Hello World!</h2>';
print '</body>';
print '</html>';

1;

For the PAR::Packer test executable, this is compiled using just pp -o parpacker_test.exe test.pl. For the PerlApp test executable, I compiled using perlapp --exe perlapp_example.exe test.pl.

Non-Working Temp PAR cache directory contents

C:\Windows\Temp\par-414b554c50412d44455624\ directory contents:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/1/2021   5:33 PM                cache-93c4d81e1f9fc1ccb321da4d056f0d78e2a44841

C:\Windows\Temp\par-414b554c50412d44455624\cache-93c4d81e1f9fc1ccb321da4d056f0d78e2a44841 directory contents:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         4/1/2021   5:33 PM          76288 libgcc_s_seh-1.dll
-a----         4/1/2021   5:33 PM        1424384 libstdc++-6.dll
-a----         4/1/2021   5:33 PM          52224 libwinpthread-1.dll
-a----         4/1/2021   5:33 PM          78848 parpacker_test.exe
-a----         4/1/2021   5:33 PM        3234816 perl530.dll

Working Temp PAR cache directory contents

C:\Users\MyUSER\AppData\Local\Temp\2\par-616e647265772e6b756c7061 directory contents:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/1/2021   5:04 PM                cache-522d9f0811561fc3f902af2285fca57cbad3e26d
d-----         4/1/2021   5:04 PM                cache-71e892043d28332eab6e4f5d98e289b6c0ece2d5
d-----         4/1/2021   5:04 PM                cache-93c4d81e1f9fc1ccb321da4d056f0d78e2a44841

cache-522d9f0811561fc3f902af2285fca57cbad3e26d directory contents:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         4/1/2021   5:04 PM          76288 libgcc_s_seh-1.dll
-a----         4/1/2021   5:04 PM        1424384 libstdc++-6.dll
-a----         4/1/2021   5:04 PM          52224 libwinpthread-1.dll
-a----         4/1/2021   5:04 PM          78848 parlz4Vl.exe
-a----         4/1/2021   5:04 PM        3234816 perl530.dll

cache-71e892043d28332eab6e4f5d98e289b6c0ece2d5 directory contents:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         4/1/2021   5:04 PM          13175 0086c683.pm
[for brevity, the remaining 87 .pm files like the one above were removed from the list.]
-a----         4/1/2021   5:04 PM          18432 36e8ac46.dll
-a----         4/1/2021   5:04 PM          47616 37ae5d86.dll
-a----         4/1/2021   5:04 PM         128000 434a9666.dll
-a----         4/1/2021   5:04 PM          54272 4ea903ad.dll
-a----         4/1/2021   5:04 PM          19456 77b87ac7.dll
-a----         4/1/2021   5:04 PM          73216 7b823064.dll
-a----         4/1/2021   5:04 PM         139264 93c4f6c2.dll
-a----         4/1/2021   5:04 PM          23552 b6881cac.dll
-a----         4/1/2021   5:04 PM          28160 b9fa593c.dll
-a----         4/1/2021   5:04 PM          23040 c501da06.dll
-a----         4/1/2021   5:04 PM          25088 dc43aa2b.dll
-a----         4/1/2021   5:04 PM          30208 e525790c.dll
-a----         4/1/2021   5:04 PM          67072 fb20c4cc.dll
-a----         4/1/2021   5:04 PM          20992 fcb949b8.dll
-a----         4/1/2021   5:04 PM          76288 libgcc_s_seh-1.dll
-a----         4/1/2021   5:04 PM        1424384 libstdc++-6.dll
-a----         4/1/2021   5:04 PM          52224 libwinpthread-1.dll
-a----         4/1/2021   5:04 PM          78848 parlloNY92L.exe
-a----         4/1/2021   5:04 PM        3234816 perl530.dll

cache-93c4d81e1f9fc1ccb321da4d056f0d78e2a44841 directory contents:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/1/2021   5:04 PM                inc
-a----         4/1/2021   5:04 PM          13175 0086c683.pm
[for brevity, the remaining 87 .pm files like the one above were removed from the list.]
-a----         4/1/2021   5:04 PM          18432 36e8ac46.dll
-a----         4/1/2021   5:04 PM          47616 37ae5d86.dll
-a----         4/1/2021   5:04 PM         128000 434a9666.dll
-a----         4/1/2021   5:04 PM          54272 4ea903ad.dll
-a----         4/1/2021   5:04 PM            723 742afc26.pl
-a----         4/1/2021   5:04 PM          19456 77b87ac7.dll
-a----         4/1/2021   5:04 PM          73216 7b823064.dll
-a----         4/1/2021   5:04 PM            324 9137dde8.pl
-a----         4/1/2021   5:04 PM         139264 93c4f6c2.dll
-a----         4/1/2021   5:04 PM          23552 b6881cac.dll
-a----         4/1/2021   5:04 PM          28160 b9fa593c.dll
-a----         4/1/2021   5:04 PM          23040 c501da06.dll
-a----         4/1/2021   5:04 PM          25088 dc43aa2b.dll
-a----         4/1/2021   5:04 PM          30208 e525790c.dll
-a----         4/1/2021   5:04 PM          67072 fb20c4cc.dll
-a----         4/1/2021   5:04 PM          20992 fcb949b8.dll
-a----         4/1/2021   5:04 PM              0 inc.lock
-a----         4/1/2021   5:04 PM          76288 libgcc_s_seh-1.dll
-a----         4/1/2021   5:04 PM        1424384 libstdc++-6.dll
-a----         4/1/2021   5:04 PM          52224 libwinpthread-1.dll
-a----         4/1/2021   5:04 PM          78848 parpacker_test.exe
-a----         4/1/2021   5:04 PM        3234816 perl530.dll
-a----        3/31/2021   5:04 PM            183 _CANARY_.txt

Additional Details

IIS output and executable failure with 502 response code doesn't change regardless of changing any of the following:

Snippet of the Trace for the Failed Request

image

rschupp commented 3 years ago

Can you check whether the executable generated by pp may get truncated (something like *nix strip) during deployment to the web server? That would explain the error message.

Andrew-Kulpa commented 3 years ago

Can you check whether the executable generated by pp may get truncated (something like *nix strip) during deployment to the web server? That would explain the error message.

The executable is the same size where I compiled it as where I deployed it. I compiled this test script in another directory and copy+pasted the file directly into C:\inetpub\wwwroot on the same server. I recompiled just to be sure and got the same file size:

-a----         4/2/2021   2:23 PM        6554784 parpacker_test.exe

The same exe can also be ran directly from powershell where it is currently installed at (C:\inetpub\wwwroot\parpacker_test.exe).

rschupp commented 3 years ago

Can you try with current master (just adds some debug output):

Andrew-Kulpa commented 3 years ago

Thank you for adding more debug logs! I cloned master and gmake installed it. The error from the HTTP Response now gives a little more information. There is also some new output from the compile command and when it works in a normal Powershell session. These are included below.

Output from GET Request to localhost/parpacker_test.exe

HTTP Error 502.2 - Bad Gateway The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "Usage: \\?\C:\inetpub\wwwroot\parpacker_test.exe [ -Alib.par ] [ -Idir ] [ -Mmodule ] [ src.par ] [ program.pl ] \\?\C:\inetpub\wwwroot\parpacker_test.exe [ -B|-b ] [-Ooutfile] src.par $progname = "\\?\C:\inetpub\wwwroot\parpacker_test.exe" $ENV{PAR_TEMP} = "C:\Windows\TEMP\par-414b554c50412d44455624\cache-5633d1b219e198affc31ccf906084dbf9a15965f" Can't find " PAR.pm " in file "\\?\C:\inetpub\wwwroot\parpacker_test.exe" ".

The contents of the par-xxx/cache-xxx look to be the same (which from my perspective is to be expected). I copied these files to a temporary, public GDrive folder here if that helps any. The working par-xxx contents should be available there too for direct comparison.

Output from Powershell With Same EXE

PS C:\inetpub\wwwroot> .\parpacker_test.exe
$progname = "C:\inetpub\wwwroot\parpacker_test.exe"
$ENV{PAR_TEMP} = "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\par-616e647265772e6b756c7061\cache-5633d1b219e198affc31ccf906084dbf9a15965f"
Unpacking FILE "cbe6d1c7/Encode.pm"...
Unpacking FILE "0c212f25/DynaLoader.pm"...
Unpacking FILE "7345ca49/Digest/base.pm"...
Unpacking FILE "4a214004/Digest/SHA.pm"...
Unpacking FILE "768ef2cf/Cwd.pm"...
Unpacking FILE "ef0f6e09/Encode/Alias.pm"...
Unpacking FILE "22a38283/Encode/Config.pm"...
Unpacking FILE "c6894f2c/Encode/Encoding.pm"...
Unpacking FILE "f11730bc/Encode/MIME/Name.pm"...
Unpacking FILE "0680b759/Errno.pm"...
Unpacking FILE "95c1e7e6/Exporter.pm"...
Unpacking FILE "3b86428e/Exporter/Heavy.pm"...
Unpacking FILE "d9cda676/Fcntl.pm"...
Unpacking FILE "f997dcc6/File/Basename.pm"...
Unpacking FILE "fd1df800/File/Copy.pm"...
Unpacking FILE "a5eb4e33/File/Find.pm"...
Unpacking FILE "06274f9f/File/Glob.pm"...
Unpacking FILE "fea6a13c/File/GlobMapper.pm"...
Unpacking FILE "415b34c5/File/Path.pm"...
Unpacking FILE "d4e7d408/File/Spec.pm"...
Unpacking FILE "c15b582c/File/Spec/Unix.pm"...
Unpacking FILE "6da3612e/File/Spec/Win32.pm"...
Unpacking FILE "d2d17fca/File/Temp.pm"...
Unpacking FILE "d41db3d4/FileHandle.pm"...
Unpacking FILE "67ad3831/IO.pm"...
Unpacking FILE "f0058b89/IO/Compress/Adapter/Deflate.pm"...
Unpacking FILE "14cbe74c/IO/Compress/Base.pm"...
Unpacking FILE "85c888af/IO/Compress/Base/Common.pm"...
Unpacking FILE "ded63ee2/IO/Compress/Gzip.pm"...
Unpacking FILE "41d7dbcd/IO/Compress/Gzip/Constants.pm"...
Unpacking FILE "9386b69e/IO/Compress/RawDeflate.pm"...
Unpacking FILE "11c905df/IO/Compress/Zlib/Extra.pm"...
Unpacking FILE "5e65e3d1/IO/File.pm"...
Unpacking FILE "f29791e5/IO/Handle.pm"...
Unpacking FILE "4d6a2d23/IO/Seekable.pm"...
Unpacking FILE "35e83274/IO/Uncompress/Adapter/Inflate.pm"...
Unpacking FILE "913b2f98/Carp/Heavy.pm"...
Unpacking FILE "c8f7799d/Compress/Zlib.pm"...
Unpacking FILE "0781ec66/Config.pm"...
Unpacking FILE "bac4ef6e/Carp.pm"...
Unpacking FILE "02d1d1e5/Compress/Raw/Zlib.pm"...
Unpacking FILE "2bb91ce8/Config_heavy.pl"...
Unpacking FILE "f0d492b4/Config_git.pl"...
Unpacking FILE "2f3d3639/IO/Uncompress/Base.pm"...
Unpacking FILE "db29fd25/IO/Uncompress/Gunzip.pm"...
Unpacking FILE "0ab0f529/IO/Uncompress/RawInflate.pm"...
Unpacking FILE "4a7d8b7a/List/Util.pm"...
Unpacking FILE "313a2498/PerlIO.pm"...
Unpacking FILE "42bec8ea/PerlIO/scalar.pm"...
Unpacking FILE "afc89260/Scalar/Util.pm"...
Unpacking FILE "a964634b/SelectSaver.pm"...
Unpacking FILE "0086c683/Storable.pm"...
Unpacking FILE "fb8eddef/Symbol.pm"...
Unpacking FILE "ee959bf2/Tie/Hash/NamedCapture.pm"...
Unpacking FILE "d9508d7c/Time/HiRes.pm"...
Unpacking FILE "ae75362e/Time/Local.pm"...
Unpacking FILE "1c8d1bc0/Win32.pm"...
Unpacking FILE "61f55ee6/XSLoader.pm"...
Unpacking FILE "4d5dd160/attributes.pm"...
Unpacking FILE "20d7dbae/base.pm"...
Unpacking FILE "eed3db5d/bytes.pm"...
Unpacking FILE "8660bea3/constant.pm"...
Unpacking FILE "0fcff0cb/integer.pm"...
Unpacking FILE "3ac62a75/lib.pm"...
Unpacking FILE "fd1c4706/overload.pm"...
Unpacking FILE "eb882dab/overloading.pm"...
Unpacking FILE "66500d37/parent.pm"...
Unpacking FILE "55eb9054/strict.pm"...
Unpacking FILE "f9238c7e/utf8.pm"...
Unpacking FILE "a80a36b2/vars.pm"...
Unpacking FILE "85b4f873/warnings.pm"...
Unpacking FILE "d51baa84/warnings/register.pm"...
Unpacking FILE "2a27ac36/PAR/Filter.pm"...
Unpacking FILE "dece6fe3/PAR/Filter/PatchContent.pm"...
Unpacking FILE "4bba698b/PAR/Filter/PodStrip.pm"...
Unpacking FILE "3bda9871/Archive/Zip.pm"...
Unpacking FILE "28aaf962/Archive/Zip/Archive.pm"...
Unpacking FILE "03653f38/Archive/Zip/DirectoryMember.pm"...
Unpacking FILE "10781775/Archive/Zip/FileMember.pm"...
Unpacking FILE "a4ac123d/Archive/Zip/Member.pm"...
Unpacking FILE "a836dd8a/Archive/Zip/NewFileMember.pm"...
Unpacking FILE "eca6e954/Archive/Zip/StringMember.pm"...
Unpacking FILE "34fb7795/Archive/Zip/ZipFileMember.pm"...
Unpacking FILE "ea5cffa2/PAR.pm"...
Unpacking FILE "2eef93bc/PAR/Dist.pm"...
Unpacking FILE "a4097d8d/PAR/Heavy.pm"...
Unpacking FILE "2e338fac/PAR/SetupProgname.pm"...
Unpacking FILE "bc490d59/PAR/SetupTemp.pm"...
Unpacking FILE "36e8ac46/auto/attributes/attributes.xs.dll"...
Unpacking FILE "37ae5d86/auto/Digest/SHA/SHA.xs.dll"...
Unpacking FILE "434a9666/auto/Storable/Storable.xs.dll"...
Unpacking FILE "4ea903ad/auto/List/Util/Util.xs.dll"...
Unpacking FILE "77b87ac7/auto/Tie/Hash/NamedCapture/NamedCapture.xs.dll"...
Unpacking FILE "7b823064/auto/Win32/Win32.xs.dll"...
Unpacking FILE "93c4f6c2/auto/Compress/Raw/Zlib/Zlib.xs.dll"...
Unpacking FILE "b6881cac/auto/Fcntl/Fcntl.xs.dll"...
Unpacking FILE "b9fa593c/auto/Time/HiRes/HiRes.xs.dll"...
Unpacking FILE "c501da06/auto/Cwd/Cwd.xs.dll"...
Unpacking FILE "dc43aa2b/auto/IO/IO.xs.dll"...
Unpacking FILE "e525790c/auto/File/Glob/Glob.xs.dll"...
Unpacking FILE "fb20c4cc/auto/Encode/Encode.xs.dll"...
Unpacking FILE "fcb949b8/auto/PerlIO/scalar/scalar.xs.dll"...
Content-type:text/html

<html><head><title>Hello</title></head><body><h2>Hello World!</h2></body></html>

Output from Compiling

PS C:\Users\andrew.kulpa\Desktop> pp -o parpacker_test.exe .\test.pl
$progname = "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\parl059Z.exe"
$ENV{PAR_TEMP} = "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\par-616e647265772e6b756c7061\cache-30c8f3caa3296cc8e6acc66eedc745ac2cef601f"
Can't find "
PAR.pm
" in file "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\parl059Z.exe"
$progname = "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\parlxAWdPYW.exe"
$ENV{PAR_TEMP} = "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\par-616e647265772e6b756c7061\cache-2bb1cb6b100ee5d4f80b97eb9a603fca3c53b9de"
Unpacking FILE "bac4ef6e/Carp.pm"...
Unpacking FILE "913b2f98/Carp/Heavy.pm"...
Unpacking FILE "02d1d1e5/Compress/Raw/Zlib.pm"...
Unpacking FILE "c8f7799d/Compress/Zlib.pm"...
Unpacking FILE "0781ec66/Config.pm"...
Unpacking FILE "f0d492b4/Config_git.pl"...
Unpacking FILE "2bb91ce8/Config_heavy.pl"...
Unpacking FILE "768ef2cf/Cwd.pm"...
Unpacking FILE "4a214004/Digest/SHA.pm"...
Unpacking FILE "7345ca49/Digest/base.pm"...
Unpacking FILE "0c212f25/DynaLoader.pm"...
Unpacking FILE "cbe6d1c7/Encode.pm"...
Unpacking FILE "ef0f6e09/Encode/Alias.pm"...
Unpacking FILE "22a38283/Encode/Config.pm"...
Unpacking FILE "c6894f2c/Encode/Encoding.pm"...
Unpacking FILE "f11730bc/Encode/MIME/Name.pm"...
Unpacking FILE "0680b759/Errno.pm"...
Unpacking FILE "95c1e7e6/Exporter.pm"...
Unpacking FILE "3b86428e/Exporter/Heavy.pm"...
Unpacking FILE "d9cda676/Fcntl.pm"...
Unpacking FILE "f997dcc6/File/Basename.pm"...
Unpacking FILE "fd1df800/File/Copy.pm"...
Unpacking FILE "a5eb4e33/File/Find.pm"...
Unpacking FILE "06274f9f/File/Glob.pm"...
Unpacking FILE "fea6a13c/File/GlobMapper.pm"...
Unpacking FILE "415b34c5/File/Path.pm"...
Unpacking FILE "d4e7d408/File/Spec.pm"...
Unpacking FILE "c15b582c/File/Spec/Unix.pm"...
Unpacking FILE "6da3612e/File/Spec/Win32.pm"...
Unpacking FILE "d2d17fca/File/Temp.pm"...
Unpacking FILE "d41db3d4/FileHandle.pm"...
Unpacking FILE "67ad3831/IO.pm"...
Unpacking FILE "f0058b89/IO/Compress/Adapter/Deflate.pm"...
Unpacking FILE "14cbe74c/IO/Compress/Base.pm"...
Unpacking FILE "85c888af/IO/Compress/Base/Common.pm"...
Unpacking FILE "ded63ee2/IO/Compress/Gzip.pm"...
Unpacking FILE "41d7dbcd/IO/Compress/Gzip/Constants.pm"...
Unpacking FILE "9386b69e/IO/Compress/RawDeflate.pm"...
Unpacking FILE "11c905df/IO/Compress/Zlib/Extra.pm"...
Unpacking FILE "5e65e3d1/IO/File.pm"...
Unpacking FILE "f29791e5/IO/Handle.pm"...
Unpacking FILE "4d6a2d23/IO/Seekable.pm"...
Unpacking FILE "35e83274/IO/Uncompress/Adapter/Inflate.pm"...
Unpacking FILE "2f3d3639/IO/Uncompress/Base.pm"...
Unpacking FILE "db29fd25/IO/Uncompress/Gunzip.pm"...
Unpacking FILE "0ab0f529/IO/Uncompress/RawInflate.pm"...
Unpacking FILE "4a7d8b7a/List/Util.pm"...
Unpacking FILE "313a2498/PerlIO.pm"...
Unpacking FILE "42bec8ea/PerlIO/scalar.pm"...
Unpacking FILE "afc89260/Scalar/Util.pm"...
Unpacking FILE "a964634b/SelectSaver.pm"...
Unpacking FILE "0086c683/Storable.pm"...
Unpacking FILE "fb8eddef/Symbol.pm"...
Unpacking FILE "ee959bf2/Tie/Hash/NamedCapture.pm"...
Unpacking FILE "d9508d7c/Time/HiRes.pm"...
Unpacking FILE "ae75362e/Time/Local.pm"...
Unpacking FILE "1c8d1bc0/Win32.pm"...
Unpacking FILE "61f55ee6/XSLoader.pm"...
Unpacking FILE "4d5dd160/attributes.pm"...
Unpacking FILE "93c4f6c2/auto/Compress/Raw/Zlib/Zlib.xs.dll"...
Unpacking FILE "c501da06/auto/Cwd/Cwd.xs.dll"...
Unpacking FILE "37ae5d86/auto/Digest/SHA/SHA.xs.dll"...
Unpacking FILE "fb20c4cc/auto/Encode/Encode.xs.dll"...
Unpacking FILE "b6881cac/auto/Fcntl/Fcntl.xs.dll"...
Unpacking FILE "e525790c/auto/File/Glob/Glob.xs.dll"...
Unpacking FILE "dc43aa2b/auto/IO/IO.xs.dll"...
Unpacking FILE "4ea903ad/auto/List/Util/Util.xs.dll"...
Unpacking FILE "fcb949b8/auto/PerlIO/scalar/scalar.xs.dll"...
Unpacking FILE "434a9666/auto/Storable/Storable.xs.dll"...
Unpacking FILE "77b87ac7/auto/Tie/Hash/NamedCapture/NamedCapture.xs.dll"...
Unpacking FILE "b9fa593c/auto/Time/HiRes/HiRes.xs.dll"...
Unpacking FILE "7b823064/auto/Win32/Win32.xs.dll"...
Unpacking FILE "36e8ac46/auto/attributes/attributes.xs.dll"...
Unpacking FILE "20d7dbae/base.pm"...
Unpacking FILE "eed3db5d/bytes.pm"...
Unpacking FILE "8660bea3/constant.pm"...
Unpacking FILE "0fcff0cb/integer.pm"...
Unpacking FILE "3ac62a75/lib.pm"...
Unpacking FILE "fd1c4706/overload.pm"...
Unpacking FILE "eb882dab/overloading.pm"...
Unpacking FILE "66500d37/parent.pm"...
Unpacking FILE "55eb9054/strict.pm"...
Unpacking FILE "f9238c7e/utf8.pm"...
Unpacking FILE "a80a36b2/vars.pm"...
Unpacking FILE "85b4f873/warnings.pm"...
Unpacking FILE "d51baa84/warnings/register.pm"...
Unpacking FILE "2a27ac36/PAR/Filter.pm"...
Unpacking FILE "dece6fe3/PAR/Filter/PatchContent.pm"...
Unpacking FILE "4bba698b/PAR/Filter/PodStrip.pm"...
Unpacking FILE "3bda9871/Archive/Zip.pm"...
Unpacking FILE "28aaf962/Archive/Zip/Archive.pm"...
Unpacking FILE "03653f38/Archive/Zip/DirectoryMember.pm"...
Unpacking FILE "10781775/Archive/Zip/FileMember.pm"...
Unpacking FILE "a4ac123d/Archive/Zip/Member.pm"...
Unpacking FILE "a836dd8a/Archive/Zip/NewFileMember.pm"...
Unpacking FILE "eca6e954/Archive/Zip/StringMember.pm"...
Unpacking FILE "34fb7795/Archive/Zip/ZipFileMember.pm"...
Unpacking FILE "ea5cffa2/PAR.pm"...
Unpacking FILE "2eef93bc/PAR/Dist.pm"...
Unpacking FILE "a4097d8d/PAR/Heavy.pm"...
Unpacking FILE "2e338fac/PAR/SetupProgname.pm"...
Unpacking FILE "bc490d59/PAR/SetupTemp.pm"...
No zip found after FILE section in file "C:\Users\ANDREW~1.KUL\AppData\Local\Temp\2\parlxAWdPYW.exe"
rschupp commented 3 years ago

Output from GET Request to localhost/parpacker_test.exe ...

$progname = "\\?\C:\inetpub\wwwroot\parpacker_test.exe"
$ENV{PAR_TEMP} = "C:\Windows\TEMP\par-414b554c50412d44455624\cache-5633d1b219e198affc31ccf906084dbf9a15965f"
Can't find " PAR.pm " in file "\\?\C:\inetpub\wwwroot\parpacker_test.exe" 
Andrew-Kulpa commented 3 years ago

Nice catch.\\?\C:\inetpub\wwwroot\parpacker_test.exe totally doesn't work from Powershell. I've found the following do work though:

Digging into this further, I found that the file size wasn't returning anything for that \\?\ prefixed path. To try and understand this a little better, I tried using another Perl module called Win32::LongPath along with the MAGIC: {} block from par.pl. I am assuming -s and stat don't handle the extended-length prefix as statL from Win32::LongPath worked perfectly. Here's the test script I used to demonstrate this:

use strict;
use warnings;
use File::stat qw( stat );
use Win32::LongPath qw(:funcs :volflags);

my $odd_filename = '\\\\?\C:\inetpub\wwwroot\parpacker_test.exe';
# my $working_filename = '\\\\.\C:\inetpub\wwwroot\parpacker_test.exe';
# my $norm_filename = 'C:\inetpub\wwwroot\parpacker_test.exe';

print $odd_filename . "\n";

my $progname = $odd_filename;
my $PAR_MAGIC = "\nPAR.pm\n";
my ($start_pos, $data_pos);
MAGIC: {
    local $SIG{__WARN__} = sub {};

    # Check file type, get start of data section {{{
    unless (open _FH, '<:raw', $progname) {
        print(qq[Can't read from file "$progname"]);  # don't use $! here as it requires Errno.pm
        last MAGIC;
    }

    # Search for the "\nPAR.pm\n signature backward from the end of the file
    my $buf;
    my $_size = -s $progname;
    print(qq[size of $progname with '-s' is ' $_size '\n]);
    my $size = (statL $progname)->{size};
    print(qq[size of $progname with statL is ' $size '\n]);
    my $chunk_size = 64 * 1024;
    my $magic_pos;

    if ($size <= $chunk_size) {
        $magic_pos = 0;
    } elsif ((my $m = $size % $chunk_size) > 0) {
        $magic_pos = $size - $m;
    } else {
        $magic_pos = $size - $chunk_size;
    }
    # in any case, $magic_pos is a multiple of $chunk_size

    while ($magic_pos >= 0) {
        seek _FH, $magic_pos, 0;
        read _FH, $buf, $chunk_size + length($PAR_MAGIC);
        if ((my $i = rindex($buf, $PAR_MAGIC)) >= 0) {
            $magic_pos += $i;
            last;
        }
        $magic_pos -= $chunk_size;
    }
    if ($magic_pos < 0) {
        print(qq[Can't find "$PAR_MAGIC" in file "$progname"]);
        last MAGIC;
    }
}

1;

The output of this on my local environment was:

PS C:\Users\andrew.kulpa\Desktop> perl .\par_test_read_file.pl
\\?\C:\inetpub\wwwroot\parpacker_test.exe
size of \\?\C:\inetpub\wwwroot\parpacker_test.exe with '-s' is '  '
size of \\?\C:\inetpub\wwwroot\parpacker_test.exe with statL is ' 6554869 '

Note, I believe you should be able to prefix any legit absolute path with a properly escaped \\?\ to reproduce this by replacing the $odd_filename value.

Andrew-Kulpa commented 3 years ago

I found that the shortpathL and abspathL subroutine from Win32::LongPath called a _denormalize_path subroutine that just strips out the \\?\ prefix. The reason why I called out these two subroutines is that they do return a usable filepath. So, maybe the same, simple sanitization process could be applied here without adding any additional dependencies?

Here's an additional code snippet demonstrating these functions and the output:

use strict;
use warnings;
use Win32::LongPath qw(:funcs :volflags);

my $odd_filename = '\\\\?\C:\inetpub\wwwroot\parpacker_test.exe';

print $odd_filename . "\n";

print "longpath " . Win32::GetLongPathName($odd_filename) . "\n";
# -> longpath \\?\C:\inetpub\wwwroot\parpacker_test.exe
print "shortpath " . Win32::GetShortPathName($odd_filename) . "\n";
# -> shortpath \\?\C:\inetpub\wwwroot\PARPAC~1.EXE
print "shortpathL " . shortpathL($odd_filename) . "\n";
# -> shortpathL C:\inetpub\wwwroot\PARPAC~1.EXE
print "abspathL " . abspathL($odd_filename) . "\n";
# -> abspathL C:\inetpub\wwwroot\parpacker_test.exe
rschupp commented 3 years ago

Thanks for the investigation.

Digging into this further, I found that the file size wasn't returning anything for that \?\ prefixed path.

This confirms my suspicion after reading the remark Many but not all file I/O APIs support "\\?\"; you should look at the reference topic for each API to be sure. in https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

But then the fix should be easy, just replace

    my $size = -s $progname;

on line 243 of script/par.pl with

    my $size = -s _FH;
Andrew-Kulpa commented 3 years ago

Thanks for the investigation.

Digging into this further, I found that the file size wasn't returning anything for that \?\ prefixed path.

This confirms my suspicion after reading the remark Many but not all file I/O APIs support "\?\"; you should look at the reference topic for each API to be sure. in https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file

But then the fix should be easy, just replace

    my $size = -s $progname;

on line 243 of script/par.pl with

    my $size = -s _FH;

Yeah, thats an awesome and simple fix. It totally worked. I patched that line locally, gmake installed, recompiled the script, and deployed it again to the IIS site with perfect results (after turning off the GLOBAL_PAR_DEBUG env var): image

rschupp commented 3 years ago

Thanks, applied