Skip to content

Commit

Permalink
[WIP] fix up padding when writing DictionaryProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Feb 10, 2024
1 parent aaaa238 commit 9245248
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion sources/OpenMcdf.Extensions/OLEProperties/DictionaryProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,31 @@ public void Read(BinaryReader br)

public void Write(BinaryWriter bw)
{
long curPos = bw.BaseStream.Position;

bw.Write(entries.Count);

foreach (KeyValuePair<uint, string> kv in entries)
{
bw.Write(kv.Key);

string s = kv.Value;
if (!s.EndsWith("\0"))
s += "\0";
bw.Write(Encoding.GetEncoding(this.codePage).GetBytes(s));

var nameBytes = Encoding.GetEncoding(this.codePage).GetBytes(s);

bw.Write(nameBytes.Length);
bw.Write(nameBytes);
}

var size = (int)(bw.BaseStream.Position - curPos);
var m = (int)size % 4;

if (m > 0)
for (int i = 0; i < m; i++) // padding
bw.Write((byte)0);

}
}
}

0 comments on commit 9245248

Please sign in to comment.