ironfede / openmcdf

Microsoft Compound File .net component - pure C# - netstandard 2.0
Mozilla Public License 2.0
297 stars 73 forks source link

Storage object creation doesn't follow the specification #68

Closed Sonic-The-Hedgehog-LNK1123 closed 3 years ago

Sonic-The-Hedgehog-LNK1123 commented 3 years ago

See the below quote from the specification:

If an implementation of the file format enables applications to create storage objects without explicitly setting an object class GUID, it MUST write all zeroes by default. If this value is not all zeroes, the object class GUID can be used as a parameter to start applications.

To fix this, change:

https://github.com/ironfede/openmcdf/blob/04b53dc16e89fd5ad1990d5fdbd234719d78d694/sources/OpenMcdf/DirectoryEntry.cs#L190

To:

 = Guid.Empty;

This change makes the switch block:

https://github.com/ironfede/openmcdf/blob/04b53dc16e89fd5ad1990d5fdbd234719d78d694/sources/OpenMcdf/DirectoryEntry.cs#L54

even more redundant than it already was, you're setting member variables to zero that you're already initialized to zero at their declaration. Also, this:

https://github.com/ironfede/openmcdf/blob/04b53dc16e89fd5ad1990d5fdbd234719d78d694/sources/OpenMcdf/DirectoryEntry.cs#L58

is one of the most inefficient ways to set a GUID to Guid.Empty.

Replacing that switch block with this if statement:

if (stgType == StgType.StgStorage)
{
    this.creationDate = BitConverter.GetBytes((DateTime.Now.ToFileTime()));
}

will have the same effect as that switch block.

ironfede commented 3 years ago

Thank you for your advices. Best Regards, Federico