Skip to content

Commit

Permalink
Bug fix #4: wrong stream size parsing in some version 3 compound docu…
Browse files Browse the repository at this point in the history
…ments not 100% specs compliant
  • Loading branch information
ironfede committed Jun 2, 2017
1 parent a75fd77 commit 6959ba2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
8 changes: 4 additions & 4 deletions sources/OpenMcdf/CompoundFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,9 @@ private void AllocateFATSectorChain(List<Sector> sectorChain)
new StreamView(
fatSectors,
GetSectorSize(),
header.FATSectorsNumber * GetSectorSize(),
null,
sourceStream,
header.FATSectorsNumber * GetSectorSize(),
null,
sourceStream,
true
);

Expand Down Expand Up @@ -1801,7 +1801,7 @@ IDirectoryEntry de
= DirectoryEntry.New(String.Empty, StgType.StgInvalid, directoryEntries);

//We are not inserting dirs. Do not use 'InsertNewDirectoryEntry'
de.Read(dirReader);
de.Read(dirReader, this.Version);

}
}
Expand Down
16 changes: 14 additions & 2 deletions sources/OpenMcdf/DirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void Write(Stream stream)
// return ms.ToArray();
//}

public void Read(Stream stream)
public void Read(Stream stream, CFSVersion ver = CFSVersion.Ver_3)
{
StreamRW rw = new StreamRW(stream);

Expand All @@ -404,7 +404,19 @@ public void Read(Stream stream)
creationDate = rw.ReadBytes(8);
modifyDate = rw.ReadBytes(8);
startSetc = rw.ReadInt32();
size = rw.ReadInt64();

if (ver == CFSVersion.Ver_3)
{
// avoid dirty read for version 3 files (max size: 32bit integer)
// where most significant bits are not initialized to zero

size = rw.ReadInt32();
rw.ReadBytes(4); //discard most significant 4 (possibly) dirty bytes
}
else
{
size = rw.ReadInt64();
}
}

public string Name
Expand Down
2 changes: 1 addition & 1 deletion sources/OpenMcdf/IDirectoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal interface IDirectoryEntry : IComparable, IRBNode
byte[] ModifyDate { get; set; }
string Name { get; }
ushort NameLength { get; set; }
void Read(System.IO.Stream stream);
void Read(System.IO.Stream stream, CFSVersion ver = CFSVersion.Ver_3);
int RightSibling { get; set; }
void SetEntryName(string entryName);
int SID { get; set; }
Expand Down
22 changes: 12 additions & 10 deletions sources/Structured Storage Explorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,20 +454,22 @@ private void treeView1_MouseUp(object sender, MouseEventArgs e)
exportDataToolStripMenuItem.Enabled = false;
}

propertyGrid1.SelectedObject = n.Tag;

if (n != null)
propertyGrid1.SelectedObject = n.Tag;


CFStream targetStream = n.Tag as CFStream;
if (targetStream != null)
{
this.hexEditor.ByteProvider = new StreamDataProvider(targetStream);
}
else
if (n != null)
{
this.hexEditor.ByteProvider = null;
CFStream targetStream = n.Tag as CFStream;
if (targetStream != null)
{
this.hexEditor.ByteProvider = new StreamDataProvider(targetStream);
}
else
{
this.hexEditor.ByteProvider = null;
}
}

}

void hexEditor_ByteProviderChanged(object sender, EventArgs e)
Expand Down

0 comments on commit 6959ba2

Please sign in to comment.