runtime icon indicating copy to clipboard operation
runtime copied to clipboard

ilasm -OUTPUT parameter does not handle long paths well on Unix

Open mellinoe opened this issue 9 years ago • 10 comments

I'm finally looking into adopting the CoreCLR version of ilasm for use in corefx (building our one .ilproj file there). Everything works okay on the Windows version, but I'm seeing that the Unix ilasm does not work correctly if the path it is passed to -OUTPUT is too long. Here's a sample command that does not work:

/home/eric/corefx/Tools/ilasm/ilasm -QUIET -DLL  -INCLUDE=include/netstandard -KEY=/home/eric/corefx/Tools/MSFT.snk System.Runtime.CompilerServices.Unsafe.il -OUTPUT:/home/eric/corefx/bin/obj/AnyOS.AnyCPU.Debug/System.Runtime.CompilerServices.Unsafe/netstandard/System.Runtime.CompilerServices.Unsafe.dll
Error : Invalid Option: -OUTPUT:/home/eric/corefx/bin/obj/AnyOS.AnyCPU.Debug/System.Runtime.CompilerServices.Unsafe/netstandard/System.Runtime.CompilerServices.Unsafe.dll


Usage: ilasm [Options] <sourcefile> [Options]
... <cut>

Here's a command that does work:

/home/eric/corefx/Tools/ilasm/ilasm -QUIET -DLL  -INCLUDE=include/netstandard -KEY=/home/eric/corefx/Tools/MSFT.snk System.Runtime.CompilerServices.Unsafe.il -OUTPUT:/home/eric/corefx/bin/System.Runtime.CompilerServices.Unsafe.dll

I just chopped a bunch of characters from the middle of the output path. This seems broken to me, but is there possibly something else that I'm doing wrong?

mellinoe avatar Feb 24 '17 00:02 mellinoe

@adiaaida Any ideas?

mellinoe avatar Feb 24 '17 00:02 mellinoe

According to my experiments, it starts failing if the OUTPUT parameter is 121 characters or longer. With 120 characters, it works fine.

mellinoe avatar Feb 24 '17 01:02 mellinoe

I'd have to look into it. My familiarity with ilasm is actually pretty minimal. @RussKeldorph Any thoughts?

michellemcdaniel avatar Feb 24 '17 01:02 michellemcdaniel

@adiaaida @mellinoe No idea, but smells like a MultiByteToWideChar (or vice versa) bytecount bug (2 * 121 is approaching _MAX_PATH). We should at least get this to support _MAX_PATH, which I assume it does on Windows, but if it's easy we should remove Windows-specific path limits on other platforms while we're at it.

RussKeldorph avatar Feb 24 '17 01:02 RussKeldorph

@mellinoe It appears to be a bit simpler than I thought. Easy fix to bump it up arbitrarily. A more elegant fix that defers to platform limits is more involved, obviously.

RussKeldorph avatar Feb 24 '17 11:02 RussKeldorph

@RussKeldorph I see, so we're essentially hard-limited to 128 characters right now? That makes sense if you count the extra 8 characters from -OUTPUT:, as well.

mellinoe avatar Feb 24 '17 20:02 mellinoe

I verified that simply changing that line to char szOpt[1024]; fixes the problem (or at least raises the limit to something more reasonable). Is that an acceptable short-term fix that I could submit?

mellinoe avatar Feb 24 '17 22:02 mellinoe

@mellinoe maybe good enough to close this

danmoseley avatar Feb 28 '17 00:02 danmoseley

It seems issue has been fixed in dotnet/coreclr#9782.

rartemev avatar Apr 05 '17 23:04 rartemev

No, this simply increased the limit to an arbitrary number. Ideally, we would remove this arbitrary limit and simply defer to any length limits on the local system. I think that the argument processing only ever looks at the first three characters of an option, so there seems to be little reason to keep a large buffer in this case, though I could be missing something.

RussKeldorph avatar Apr 06 '17 00:04 RussKeldorph