runtime icon indicating copy to clipboard operation
runtime copied to clipboard

FileStream constructor fails with Release builds of CoreCLR

Open fadimounir opened this issue 10 years ago • 4 comments

Seems like an issue with StringBuffers. Here is a simple repro:

// NOTE: Uses the System.IO.FileStream class from the System.IO.FileSystem.dll assembly using System.IO; static int Main(string[] args) { using (StreamReader sr = new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read), Encoding.UTF8)) { string response = sr.ReadToEnd(); } }

Passing in something like "D:\MyPath\MyFile.txt". From the call to FileStream..ctor(...), we get a call to PathHelpers.GetFullPathName(path) in System.Runtime.Extensions.dll. The return path from the GetFullPathName API becomes "??D:\MyPath\MyFile.t" (first 2 characters are garbage).

This repro runs correctly with a Debug build of coreclr.dll. Repro'd on x64.

Exception: Unhandled Exception: System.ArgumentException: Illegal characters in path. Parameter name: path at System.IO.PathHelper.Normalize(String path, Boolean checkInvalidCharacters, Boolean expandShortPaths) at System.IO.Path.NormalizeAndValidatePath(String path) at System.IO.Path.GetFullPath(String path) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at Program.Main(String[] args)

In Normalize(), we call PathHelper.GetFullPathName, which returns the path with invalid characters, and causes Normalize() to throw the ArgumentException.

fadimounir avatar Mar 17 '16 23:03 fadimounir

@JeremyKuhne is this a recent regression?

joshfree avatar Mar 23 '16 17:03 joshfree

@fadimounir I'm not seeing this behavior- looking at your stack it should be failing any API that takes a path, have you seen failures elsewhere?

JeremyKuhne avatar Mar 23 '16 23:03 JeremyKuhne

Moving out of RC2 as we cannot currently repro it. @fadimounir if you can help us figure out a repro that would help us track it down.

weshaggard avatar Mar 24 '16 23:03 weshaggard

Going to close this issue, please reopen if you find a repro.

JeremyKuhne avatar May 13 '16 18:05 JeremyKuhne