From 36607b791314b301aee8e8ab21afb1f82a9fc92b Mon Sep 17 00:00:00 2001 From: LTRData Date: Wed, 16 Oct 2024 18:17:08 +0200 Subject: [PATCH] Fixed some FAT exceptions * Fixed NullReferenceException when parameter object was not supplied to file system class. * Fixed dictionary exception for FAT with volume name entry, when volume name matched a file name in root directory. --- Library/DiscUtils.Fat/Directory.cs | 8 ++++++-- Library/DiscUtils.Fat/FatFileSystemOptions.cs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/DiscUtils.Fat/Directory.cs b/Library/DiscUtils.Fat/Directory.cs index 3feb3f4c..35dc9df1 100644 --- a/Library/DiscUtils.Fat/Directory.cs +++ b/Library/DiscUtils.Fat/Directory.cs @@ -420,9 +420,13 @@ internal void UpdateEntry(long id, DirectoryEntry entry) private void AddEntryRaw(long pos, DirectoryEntry entry) { _entries.Add(pos, entry); + // Update the short and full name lookup tables - _shortFileNameToEntry.Add(entry.Name.ShortName, pos); - _fullFileNameToEntry.Add(entry.Name.FullName, pos); + if (!entry.Attributes.HasFlag(FatAttributes.VolumeId)) + { + _shortFileNameToEntry.Add(entry.Name.ShortName, pos); + _fullFileNameToEntry.Add(entry.Name.FullName, pos); + } } private void LoadEntries() diff --git a/Library/DiscUtils.Fat/FatFileSystemOptions.cs b/Library/DiscUtils.Fat/FatFileSystemOptions.cs index 5117ad19..2237413e 100644 --- a/Library/DiscUtils.Fat/FatFileSystemOptions.cs +++ b/Library/DiscUtils.Fat/FatFileSystemOptions.cs @@ -39,7 +39,7 @@ internal FatFileSystemOptions() internal FatFileSystemOptions(FileSystemParameters parameters) { - if (parameters.FileNameEncoding is not null) + if (parameters?.FileNameEncoding is not null) { FileNameEncoding = parameters.FileNameEncoding; }