microsoft / winfile

Original Windows File Manager (winfile) with enhancements
MIT License
6.75k stars 698 forks source link

Bug - Menu >> File >> Run for long command line gets truncated #394

Closed ScottHollows closed 1 year ago

ScottHollows commented 1 year ago

Symptoms Running a very long command from Menu >> File >> Run results in the command getting truncated somewhere around 255 character and some extra junk characters get added to the command

Example

1) Menu >> File >> Run

2) Enter this in the command line field

MyProgram.exe /aaaaaaaaaaaaaaaaaa=aaaaaaaaaaaaaaaaaaaaa /bbbbbbbbbbbbbbbbbbbb=bbbbbbbbbbbbbbbbbbbbbbbbb /cccccccccccccccccc=cccccccccccccccc /ddddddddddddddd=dddddddddddddddd /eeeeeeeeeeeeeeeeeee=eeeeeeeeeeeeeeeeee /ffffffffffffffff=ffffffffffffffffffffff /ggggggggggggggggg=ggggggggggggggggggggggggggg /hhhhhhhhhhhhhhhhhhhhh=hhhhhhhhhhhhhhhhhhh /iiiiiiiiiiiiiiiiiiiiiiii=iiiiiiiiiiiiiiiiiiiiii /jjjjjjjjjjjjjjjjjjjj=jjjjjjjjjjjjjjjjjjjjj /kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk=kkkkkkkkkkkkkkkkkkkkkkkkkk /llllllllllllllllllllll=lllllllllllllllllllll

3) Press OK

4) The command gets truncated around 255 characters and junk characters are added to the end

MyProgram.exe /aaaaaaaaaaaaaaaaaa=aaaaaaaaaaaaaaaaaaaaa /bbbbbbbbbbbbbbbbbbbb=bbbbbbbbbbbbbbbbbbbbbbbbb /cccccccccccccccccc=cccccccccccccccc /ddddddddddddddd=dddddddddddddddd /eeeeeeeeeeeeeeeeeee=eeeeeeeeeeeeeeeeee /ffffffffffffffff=fffffffffffffffffffff??? d

Use Case In my application, the field values can be specified on the command line which can result in a very long command line

Change Request Please remove the limit or increase it to perhaps 1000 characters

schinagl commented 1 year ago

Are you using Winfile 10.2.0.0? How did you determine that the args were garbled? Printing the args from MyProgram.exe?

If I debug Winfile the args 'leave' winfile via ShellExecute() in shape. Are you sure the problem is not in MyProgram.exe when printing the args? As far as I remember command lines are limited to 255 characters, but I could be wrong.

malxau commented 1 year ago

@ScottHollows I'd second schinagl's question - which release are you using? Also, which version of Windows?

I think the limitation is in RunDlgProc. Prior to #340 , this was limited to 260 chars (total.) In the latest release this should be over 1000.

Unfortunately that doesn't explain:

Originally the code used a different constant for the parameter buffer length compared to the total buffer length, which seems unsafe, but as far as I can tell in this repo they always had the same value. If there was a build where RUN_LENGTH < MAXPATHLEN, this could happen.

schinagl commented 1 year ago

@malxau : I hooked up with the debugger, then exactly entered the string specified by @ScottHollows, and was able see that it was fed into ShellExecute() exactly the right way.

So @ScottHollows please check MyProgramm.exe if it handles args properly

ScottHollows commented 1 year ago

I wrote a test program that shows the parameters passed in to it and the length of the parameters

It runs ok from a DOS command line with 5000 characters It also runs ok when called from a DOS batch program with 5000 characters

When I run it from File Manager > File Run it gets truncated around 1000 characters, with a bit of wiggle room that is probably the length of the program name

I have identified at least one issue where the File Run > Command Line field is limited to 1000 characters so there is no way to test parameters longer than that That 1000 limit is longer than the original 255 that I reported in my original post so must have done that test incorrectly - sorry about that. At a guess, I probably ran an older version of File Manager or I was running it in an virtual machine with an old version of Windows When I run that same test now in Windows 10 (22H2) it correctly shows all 255 char

So, my original post was incorrect and the limit is around 1000 rather than the 255 that I reported

Since this is under review, can the limit for that Command Line field be increased to maybe 5000 characters ?

schinagl commented 1 year ago

With #340 the length of path and all internal strings was increased to 1024.

340 is part of 10.2.0.0

Thus the arguments of a command passed to File/Run can be 1024 characters.

I suggest to use .bat files for arguments longer than 1024 characters, because handling of so many characters in this tiny File/Run box is error prone.

ScottHollows commented 1 year ago

Thanks for looking into this.

I am closing this issue now