ironfede / openmcdf

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

Ensure string values are null terminated when writing them #102

Closed Numpsy closed 9 months ago

Numpsy commented 9 months ago

refs #47

When testing adding or modifying properties, I noticed that new or modified string properties weren't getting null terminated, and that was causing issues with office apps like powerpoint which were showing truncated property values.

I went to add the null values, but it isn't quite that simple as any properties that OpenMxdf has read itself will retain the null terminators from the originating file whereas new values supplied by a user generally won't, so - try to check if the value has a trailing null already and only write an extra one if not.

This seems to work, though i'm not 100% sure on the situation with empty strings (The Windows native compound doc apis seem to set a length of 1 and include a null for empty string properties, so I've done the same)

Numpsy commented 9 months ago

Added a couple of tests, and also changed to check for the encoded byte array ending with a null instead of the input string, as it seems that

anyString.EndsWith("\0")

is always true in .NET 6