From ab465fa47a7d3c2d0efb1dc8e27fd05033c776de Mon Sep 17 00:00:00 2001 From: Michel Zehnder Date: Fri, 31 May 2024 18:11:40 +0200 Subject: [PATCH] Don't incur the penalty of validation if it's disabled. Also combin Contains with Add --- sources/OpenMcdf/CompoundFile.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sources/OpenMcdf/CompoundFile.cs b/sources/OpenMcdf/CompoundFile.cs index aadcc417..f706e118 100644 --- a/sources/OpenMcdf/CompoundFile.cs +++ b/sources/OpenMcdf/CompoundFile.cs @@ -1367,12 +1367,15 @@ int nextSecID private void EnsureUniqueSectorIndex(int nextSecID, HashSet processedSectors) { - if (processedSectors.Contains(nextSecID) && this.validationExceptionEnabled) + if (!this.validationExceptionEnabled) { - throw new CFCorruptedFileException("The file is corrupted."); + return; } - processedSectors.Add(nextSecID); + if (!processedSectors.Add(nextSecID)) + { + throw new CFCorruptedFileException("The file is corrupted."); + } } ///