ironfede / openmcdf

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

Fix #121 #124

Closed ironfede closed 2 months ago

ironfede commented 4 months ago

This pr should fix #121 . I've partially followed specifications [MS-OLEPS] I've chosen not to expose any trailing null char BUT embedded nulls will be left untouched.

As stated in note 1 to section 2.5

Windows presents properties with PropertySet VT_LPSTR (0x001E) to applications
as null-terminated string values such that the application cannot reliably detect the presence of
trailing null characters or any characters following the first embedded null character.

client application cannot detect trailing nulls after string terminator.

Waiting for some thoughts or comment before merging.

Many thanks, Federico

Numpsy commented 3 months ago

As I mentioned previously, I was able to use this branch to create a file which made Windows Explorer on my laptop crash when looking at the custom file properties (although Word seems to open the file without problems) - If I run this test

        // Modify some document summary information properties, save to a file, and then validate the expected results
        [TestMethod]
        public void Test_Empty_User_Property()
        {
            using (CompoundFile cf = new CompoundFile("2custom.doc"))
            {
                var dsiStream = cf.RootStorage.GetStream("\u0005DocumentSummaryInformation");
                var co = dsiStream.AsOLEPropertiesContainer();
                var userProperties = co.UserDefinedProperties;

                userProperties.Properties.First(prop => prop.PropertyName == "prop1").Value = "";

                co.Save(dsiStream);
                cf.SaveAs("zero_length_property.doc");
                cf.Close();
            }
        }

Does anyone else see that when looking at the custom properties sheet on the output file? e.g. image where 'prop1' should be empty now?