From 7c24a9ec3ac66236919a931db4a7df059010aef1 Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Fri, 20 Sep 2024 14:37:08 +1200 Subject: [PATCH] Header method could be a member (CS1822) --- sources/OpenMcdf/CompoundFile.cs | 30 +----------------------------- sources/OpenMcdf/Header.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/sources/OpenMcdf/CompoundFile.cs b/sources/OpenMcdf/CompoundFile.cs index 1ddd608a..1576fcc5 100644 --- a/sources/OpenMcdf/CompoundFile.cs +++ b/sources/OpenMcdf/CompoundFile.cs @@ -615,7 +615,7 @@ private void Load(Stream stream) if (!Configuration.HasFlag(CFSConfiguration.NoValidationException)) { - ValidateHeader(header); + header.ThrowIfInvalid(); } int n_sector = Ceiling((stream.Length - GetSectorSize()) / (double)GetSectorSize()); @@ -644,34 +644,6 @@ private void Load(Stream stream) } } - /// - /// Validate header values specified in [MS-CFB] document - /// - /// The Header sector of file to validate - /// If one of the validation checks fails a CFCorruptedFileException exception will be thrown - private void ValidateHeader(Header header) - { - if (header.MiniSectorShift != 6) - { - throw new CFCorruptedFileException("Mini sector Shift MUST be 0x06"); - } - - if ((header.MajorVersion == 0x0003 && header.SectorShift != 9) || (header.MajorVersion == 0x0004 && header.SectorShift != 0x000c)) - { - throw new CFCorruptedFileException("Sector Shift MUST be 0x0009 for Major Version 3 and 0x000c for Major Version 4"); - } - - if (header.MinSizeStandardStream != 4096) - { - throw new CFCorruptedFileException("Mini Stream Cut off size MUST be 4096 byte"); - } - - if (header.ByteOrder != 0xFFFE) - { - throw new CFCorruptedFileException("Byte order MUST be little endian (0xFFFE)"); - } - } - private void LoadFile(string fileName) { this.fileName = fileName; diff --git a/sources/OpenMcdf/Header.cs b/sources/OpenMcdf/Header.cs index 309e9320..6b4da8a7 100644 --- a/sources/OpenMcdf/Header.cs +++ b/sources/OpenMcdf/Header.cs @@ -167,5 +167,32 @@ private void CheckSignature() throw new CFFileFormatException("Invalid OLE structured storage file"); } } + + /// + /// Validate header values specified in [MS-CFB] document + /// + /// If one of the validation checks fails a CFCorruptedFileException exception will be thrown + internal void ThrowIfInvalid() + { + if (MiniSectorShift != 6) + { + throw new CFCorruptedFileException("Mini sector Shift MUST be 0x06"); + } + + if ((MajorVersion == 0x0003 && SectorShift != 9) || (MajorVersion == 0x0004 && SectorShift != 0x000c)) + { + throw new CFCorruptedFileException("Sector Shift MUST be 0x0009 for Major Version 3 and 0x000c for Major Version 4"); + } + + if (MinSizeStandardStream != 4096) + { + throw new CFCorruptedFileException("Mini Stream Cut off size MUST be 4096 byte"); + } + + if (ByteOrder != 0xFFFE) + { + throw new CFCorruptedFileException("Byte order MUST be little endian (0xFFFE)"); + } + } } }