dotnet / dotnet/runtime

System.IO.DriveInfo returns invalid data for mounted optical drive volume in Linux if the volume label contains space

Open
#123,347 1 comment 0 reactions 0 assignees View on GitHub
area-System.IO bug
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

When enumerating drive information using `DriveInfo.GetDrives()` the returned data may be invalid (incorrect `Name`, `DriveType`, and `RootDirectory`) for mounted optical disc if the volume label has spaces in it.
The exact same code worked in previous versions of .NET.

### Reproduction Steps

```csharp
var drives = System.IO.DriveInfo.GetDrives().ToList();
Console.WriteLine($"Found {drives.Count} drives);
foreach (var drive in drives)
{
Console.WriteLine($"{drive.Name} (type: {drive.DriveType}): {drive.RootDirectory}");
}
```

run with `dotnet run --framework 9.0 ./program.cs` vs `dotnet run ./program.cs` with dotnet-sdk-10.0 installed

### Expected behavior

`Name` and `RootDirectory` point to the mount point (usually something like `/run/media/username/DISC LABEL`), and `DriveType` == `CDRom`

### Actual behavior

`Name` and `RootDirectory` are broken (`/run/media/username/DISC\0403`), and `DriveType` == `NoRootDirectory`

### Regression?

Yes, the same code worked fine with .NET 8 and 9

### Known Workarounds

_No response_

### Configuration

Tested using .NET SDK 9.0.11 and 10.0.1 on Fedora 42, but I got reports from NixOS and Bazzite

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.