Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(linux) Managed Open Dialog window crashes if a Disk Drive Label have a space in it #4844

Closed
Jedi-Mind-Tricks opened this issue Oct 11, 2020 · 9 comments
Assignees

Comments

@Jedi-Mind-Tricks
Copy link

Initial source: VitalElement/AvalonStudio#758

To reproduce:

  1. Get USB stick or additional HDD drive with a space in it's label (in this example i had HDD 64)
  2. On Linux run an AvaloniaUI program (in my case Avalon Studio)
  3. File -> Open Solution

Result:

  • Open DIalog window never pop up. AvalonStudio crashes.
  • Stack trace:
Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path '/run/media/george/HDD\04064'.
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
   at System.IO.Enumeration.FileSystemEnumerator`1.Init()
   at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
   at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.Directory.GetFiles(String path)
   at Avalonia.Dialogs.ManagedFileChooserSources.<>c.<DefaultGetFileSystemRoots>b__17_0(MountedVolumeInfo x)
   at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Avalonia.Dialogs.ManagedFileChooserSources.DefaultGetFileSystemRoots()
   at Avalonia.Dialogs.ManagedFileChooserSources.DefaultGetAllItems(ManagedFileChooserSources sources)
   at Avalonia.Dialogs.ManagedFileChooserSources.GetAllItems()
   at Avalonia.Dialogs.ManagedFileChooserViewModel.RefreshQuickLinks(ManagedFileChooserSources quickSources)
   at Avalonia.Dialogs.ManagedFileChooserViewModel..ctor(FileSystemDialog dialog, ManagedFileDialogOptions options)
   at Avalonia.Dialogs.ManagedFileDialogExtensions.ManagedSystemDialogImpl`1.Show(SystemDialog d, Window parent, ManagedFileDialogOptions options)
   at Avalonia.Dialogs.ManagedFileDialogExtensions.ManagedSystemDialogImpl`1.ShowFileDialogAsync(FileDialog dialog, Window parent)
   at AvalonStudio.Controls.Standard.SolutionExplorer.SolutionExplorerViewModel.OpenSolution() in /home/george/AvalonStudio/AvalonStudio/AvalonStudio.Controls.Standard/SolutionExplorer/SolutionExplorerViewModel.cs:line 181
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_0(Object state)
   at Avalonia.Threading.AvaloniaSynchronizationContext.<>c__DisplayClass8_0.<Post>b__0()
   at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority)
   at Avalonia.X11.X11Window.<ScheduleInput>b__120_0()
   at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority)
   at Avalonia.X11.X11PlatformThreading.HandleX11(CancellationToken cancellationToken)
   at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode)
   at AvalonStudio.Shell.Shell.StartShellApp[TAppBuilder](TAppBuilder builder, String appName, ShellAppMainDelegate main, String[] args, IFactory layoutFactory) in /home/george/AvalonStudio/AvalonStudio.Shell/src/AvalonStudio.Shell/Shell.cs:line 17
   at AvalonStudio.Program.Main(String[] args) in /home/george/AvalonStudio/AvalonStudio/AvalonStudio/Program.cs:line 32
Aborted (core dumped)

Expected Result:

  • Open Dialog handle drive lables with spaces

Environment:

  • reproduced on Manjaro Linux x86_64, Kernel: 5.8.11-1-MANJARO
  • netcore 3.1
  • Stock AvalonStudio v 0.0.5500 (v20191224.1-22-g83364de2) commit 83364de (HEAD -> develop, origin/develop, origin/HEAD) Merge: 79e9b68 5be2aa3

Additional info:

  • reproduces with USB stick
  • reproduces with sata HDD
  • as AvalonStudio developer stated

looks like that is the bug in Avalonia's managed open file dialog Avalon Studio uses

@Jedi-Mind-Tricks Jedi-Mind-Tricks changed the title (linux) Open Dialog window crashes if a Disk Drive Lable have space (linux) Open Dialog window crashes if a Disk Drive Label have a space in it Oct 11, 2020
@maxkatz6
Copy link
Member

Can you check "System.IO.Directory.GetFiles" method with your folder in the console app?
Looking on the stacktrace, it doesn't feels like a problem is in Avalonia.
Or probably VolumePath should be unescaped first on our side.

@Jedi-Mind-Tricks
Copy link
Author

Ok, so in a test console app:

  1. if I do System.IO.Directory.GetFiles("/run/media/george/HDD\04064");
    I got:
Exception has occurred: CLR/System.ArgumentException
An unhandled exception of type 'System.ArgumentException' occurred in System.IO.FileSystem.dll: 'Illegal characters in path '{0}'.'
   at System.IO.Enumeration.FileSystemEnumerableFactory.NormalizeInputs(String& directory, String& expression, MatchType matchType)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.Directory.GetFiles(String path)
   at test.Program.Main(String[] args) in /home/george/consle/test/Program.cs:line 12
  1. if I do System.IO.Directory.GetFiles("/run/media/george/HDD 64/");
    it successfully return files.

@wuzlai
Copy link

wuzlai commented Nov 23, 2020

Hi, I had the same problem,When you open the file dialog,Control exception crashes. here is prompt
Could not find a part of the path'/media/ WZL /UOS\04020
There is a space character in the address, but What I don't understand is why this directory was opened during initialization, can't we specify other directories? I infer that the control itself has a problem

@riQQ
Copy link

riQQ commented Mar 25, 2022

As far as I can see, this was fixed by #5542, i.e. Avalonia 0.10.1 or higher.

@maxkatz6
Copy link
Member

maxkatz6 commented Mar 26, 2022

It won't crash now, but I don't think it's possible to select any files from disks with spaces in the label.
Can anybody confirm?

@maxkatz6 maxkatz6 changed the title (linux) Open Dialog window crashes if a Disk Drive Label have a space in it (linux) Managed Open Dialog window crashes if a Disk Drive Label have a space in it Jun 24, 2022
@SupinePandora43
Copy link

I think I've got similiar exception in ILSpy.

Exception Sorry, we crashed System.ArgumentException: The output byte buffer is too small to contain the encoded data, encoding 'Unicode (UTF-8)' fallback 'System.Text.EncoderReplacementFallback'. (Parameter 'bytes') at System.Text.Encoding.ThrowBytesOverflow() at System.Text.Encoding.ThrowBytesOverflow(EncoderNLS encoder, Boolean nothingEncoded) at System.Text.Encoding.GetBytesWithFallback(ReadOnlySpan`1 chars, Int32 originalCharsLength, Span`1 bytes, Int32 originalBytesLength, EncoderNLS encoder) at System.Text.Encoding.GetBytesWithFallback(Char* pOriginalChars, Int32 originalCharCount, Byte* pOriginalBytes, Int32 originalByteCount, Int32 charsConsumedSoFar, Int32 bytesWrittenSoFar) at System.Text.UTF8Encoding.GetBytes(String s, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex) at Avalonia.FreeDesktop.NativeMethods.ReadLink(String path) in /_/src/Avalonia.FreeDesktop/NativeMethods.cs:line 25 at Avalonia.FreeDesktop.LinuxMountedVolumeInfoListener.GetSymlinkTarget(String x) in /_/src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs:line 37 at Avalonia.FreeDesktop.LinuxMountedVolumeInfoListener.b__8_7(FileInfo x) in /_/src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs:line 57 at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() at System.Linq.Lookup`2.CreateForJoin(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) at System.Linq.Enumerable.GroupJoinIterator[TOuter,TInner,TKey,TResult](IEnumerable`1 outer, IEnumerable`1 inner, Func`2 outerKeySelector, Func`2 innerKeySelector, Func`3 resultSelector, IEqualityComparer`1 comparer)+MoveNext() at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext() at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source) at Avalonia.FreeDesktop.LinuxMountedVolumeInfoListener.Poll(Int64 _) in /_/src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs:line 41 at Avalonia.FreeDesktop.LinuxMountedVolumeInfoListener..ctor(ObservableCollection`1& target) in /_/src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoListener.cs:line 34 at Avalonia.FreeDesktop.LinuxMountedVolumeInfoProvider.Listen(ObservableCollection`1 mountedDrives) in /_/src/Avalonia.FreeDesktop/LinuxMountedVolumeInfoProvider.cs:line 13 at Avalonia.Dialogs.ManagedFileChooserViewModel..ctor(FileSystemDialog dialog, ManagedFileDialogOptions options) in /_/src/Avalonia.Dialogs/ManagedFileChooserViewModel.cs:line 116 at Avalonia.Dialogs.ManagedFileDialogExtensions.ManagedSystemDialogImpl`1.Show(SystemDialog d, Window parent, ManagedFileDialogOptions options) in /_/src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs:line 14 at Avalonia.Dialogs.ManagedFileDialogExtensions.ManagedSystemDialogImpl`1.ShowFileDialogAsync(FileDialog dialog, Window parent) in /_/src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs:line 42 at ICSharpCode.ILSpy.OpenFromNuGetCommand.Execute(Object parameter) in /home/runner/work/AvaloniaILSpy/AvaloniaILSpy/ILSpy.Core/Commands/OpenFromNuGetCommand.cs:line 42 at System.Threading.Tasks.Task.<>c.b__128_0(Object state) at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority) in /_/src/Avalonia.Base/Threading/JobRunner.cs:line 37 at Avalonia.X11.X11PlatformThreading.HandleX11(CancellationToken cancellationToken) in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 169 at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken) in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 245 at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 65 at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 120 at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 209 at ICSharpCode.ILSpy.Program.Main(String[] args) in /home/runner/work/AvaloniaILSpy/AvaloniaILSpy/ILSpy/Program.cs:line 22

image

@timunie
Copy link
Contributor

timunie commented Aug 28, 2023

@SupinePandora43 if you have any idea how to fix that, your PR would be welcome :-)

@SupinePandora43
Copy link

SupinePandora43 commented Aug 30, 2023

@SupinePandora43 if you have any idea how to fix that, your PR would be welcome :-)

It was a different issue, already fixed by #8134

@timunie
Copy link
Contributor

timunie commented Aug 30, 2023

acc. to feedback, I'm closing this for now. If issue presists in 11.0.4 or greater, ping me and I'll re-open it or open a new issue report.

@timunie timunie closed this as completed Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants