Skip to content

Commit 6959ba2

Browse files
committed
Bug fix #4: wrong stream size parsing in some version 3 compound documents not 100% specs compliant
1 parent a75fd77 commit 6959ba2

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

sources/OpenMcdf/CompoundFile.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,9 @@ private void AllocateFATSectorChain(List<Sector> sectorChain)
10731073
new StreamView(
10741074
fatSectors,
10751075
GetSectorSize(),
1076-
header.FATSectorsNumber * GetSectorSize(),
1077-
null,
1078-
sourceStream,
1076+
header.FATSectorsNumber * GetSectorSize(),
1077+
null,
1078+
sourceStream,
10791079
true
10801080
);
10811081

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

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

18061806
}
18071807
}

sources/OpenMcdf/DirectoryEntry.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public void Write(Stream stream)
378378
// return ms.ToArray();
379379
//}
380380

381-
public void Read(Stream stream)
381+
public void Read(Stream stream, CFSVersion ver = CFSVersion.Ver_3)
382382
{
383383
StreamRW rw = new StreamRW(stream);
384384

@@ -404,7 +404,19 @@ public void Read(Stream stream)
404404
creationDate = rw.ReadBytes(8);
405405
modifyDate = rw.ReadBytes(8);
406406
startSetc = rw.ReadInt32();
407-
size = rw.ReadInt64();
407+
408+
if (ver == CFSVersion.Ver_3)
409+
{
410+
// avoid dirty read for version 3 files (max size: 32bit integer)
411+
// where most significant bits are not initialized to zero
412+
413+
size = rw.ReadInt32();
414+
rw.ReadBytes(4); //discard most significant 4 (possibly) dirty bytes
415+
}
416+
else
417+
{
418+
size = rw.ReadInt64();
419+
}
408420
}
409421

410422
public string Name

sources/OpenMcdf/IDirectoryEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal interface IDirectoryEntry : IComparable, IRBNode
2323
byte[] ModifyDate { get; set; }
2424
string Name { get; }
2525
ushort NameLength { get; set; }
26-
void Read(System.IO.Stream stream);
26+
void Read(System.IO.Stream stream, CFSVersion ver = CFSVersion.Ver_3);
2727
int RightSibling { get; set; }
2828
void SetEntryName(string entryName);
2929
int SID { get; set; }

sources/Structured Storage Explorer/MainForm.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,22 @@ private void treeView1_MouseUp(object sender, MouseEventArgs e)
454454
exportDataToolStripMenuItem.Enabled = false;
455455
}
456456

457-
propertyGrid1.SelectedObject = n.Tag;
458-
457+
if (n != null)
458+
propertyGrid1.SelectedObject = n.Tag;
459459

460460

461-
CFStream targetStream = n.Tag as CFStream;
462-
if (targetStream != null)
463-
{
464-
this.hexEditor.ByteProvider = new StreamDataProvider(targetStream);
465-
}
466-
else
461+
if (n != null)
467462
{
468-
this.hexEditor.ByteProvider = null;
463+
CFStream targetStream = n.Tag as CFStream;
464+
if (targetStream != null)
465+
{
466+
this.hexEditor.ByteProvider = new StreamDataProvider(targetStream);
467+
}
468+
else
469+
{
470+
this.hexEditor.ByteProvider = null;
471+
}
469472
}
470-
471473
}
472474

473475
void hexEditor_ByteProviderChanged(object sender, EventArgs e)

0 commit comments

Comments
 (0)