Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the writing of offsets when writing user defined properties #106

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions sources/OpenMcdf.Extensions/OLEProperties/PropertySetStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ public void Write(System.IO.BinaryWriter bw)

var padding0 = bw.BaseStream.Position % 4;

//if (padding0 > 0)
//{
// for (int p = 0; p < padding0; p++)
// bw.Write((byte)0);
//}
if (padding0 > 0)
{
for (int p = 0; p < 4 - padding0; p++)
bw.Write((byte)0);
}

int size0 = (int)(bw.BaseStream.Position - oc0.OffsetPS);

Expand Down Expand Up @@ -183,7 +183,7 @@ public void Write(System.IO.BinaryWriter bw)

int size1 = (int)(bw.BaseStream.Position - oc1.OffsetPS);

bw.Seek(oc1.OffsetPS + 4, System.IO.SeekOrigin.Begin);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This +4 was causing it to overwrite the property count rather than the size (I ended up with a size of 0 and >100 properties, which is just wrong)

bw.Seek(oc1.OffsetPS, System.IO.SeekOrigin.Begin);
bw.Write(size1);
}

Expand Down Expand Up @@ -214,8 +214,8 @@ public void Write(System.IO.BinaryWriter bw)
{
for (int i = 0; i < PropertySet1.PropertyIdentifierAndOffsets.Count; i++)
{
bw.Seek((int)oc1.PropertyIdentifierOffsets[i], System.IO.SeekOrigin.Begin); //Offset of 4 to Offset value
bw.Write(oc1.PropertyOffsets[i] - oc1.OffsetPS);
bw.Seek((int)oc1.PropertyIdentifierOffsets[i] + 4, System.IO.SeekOrigin.Begin); //Offset of 4 to Offset value
bw.Write((int)(oc1.PropertyOffsets[i] - oc1.OffsetPS));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to match the case on lines 207/208, otherwise it was writing the offset in the wrong place, and also writing 8 bytes rather than 4

}
}
}
Expand Down