Skip to content

Commit

Permalink
Header method could be a member (CS1822)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Sep 20, 2024
1 parent f5fd74b commit 7c24a9e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
30 changes: 1 addition & 29 deletions sources/OpenMcdf/CompoundFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -644,34 +644,6 @@ private void Load(Stream stream)
}
}

/// <summary>
/// Validate header values specified in [MS-CFB] document
/// </summary>
/// <param name="header">The Header sector of file to validate</param>
/// <exception cref="CFCorruptedFileException">If one of the validation checks fails a <see cref="T:OpenMcdf.CFCorruptedFileException">CFCorruptedFileException</see> exception will be thrown</exception>
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;
Expand Down
27 changes: 27 additions & 0 deletions sources/OpenMcdf/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,32 @@ private void CheckSignature()
throw new CFFileFormatException("Invalid OLE structured storage file");
}
}

/// <summary>
/// Validate header values specified in [MS-CFB] document
/// </summary>
/// <exception cref="CFCorruptedFileException">If one of the validation checks fails a <see cref="T:OpenMcdf.CFCorruptedFileException">CFCorruptedFileException</see> exception will be thrown</exception>
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)");
}
}
}
}

0 comments on commit 7c24a9e

Please sign in to comment.