Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Loading an invalid compound document file #4

Open
nmnhut2010 opened this issue Feb 28, 2017 · 1 comment
Open

Loading an invalid compound document file #4

nmnhut2010 opened this issue Feb 28, 2017 · 1 comment
Labels

Comments

@nmnhut2010
Copy link

I found that the method CompoundFile.LoadDirectories fail to handle the case where the starting sector of a directory entry is invalid.

With the sample file FTC07.zip, the starting sector of the directory entry #42 is equal to 6553868 which is invalid. Adding the below line to Line 685, we can check directoryEntries[42].StartSetc
Console.WriteLine(directoryEntries[42].StartSetc); // 6553868

We should check de.StartSetc in the method CompoundFile.LoadDirectories. If de.StartSetc is greater than this.sectors.Count, we should raise an exception that the file is invalid.

private void LoadDirectories()
{
	List<Sector> directoryChain
		= GetSectorChain(header.FirstDirectorySectorID, SectorType.Normal);

	if (header.FirstDirectorySectorID == Sector.ENDOFCHAIN)
		header.FirstDirectorySectorID = directoryChain[0].Id;

	StreamView dirReader
		= new StreamView(directoryChain, GetSectorSize(), directoryChain.Count * GetSectorSize(), sourceStream);


	while (dirReader.Position < directoryChain.Count * GetSectorSize())
	{
		IDirectoryEntry de
		= DirectoryEntry.New(String.Empty, StgType.StgInvalid, directoryEntries);

		//We are not inserting dirs. Do not use 'InsertNewDirectoryEntry'
		de.Read(dirReader);
                // We should check de.StartSetc here
                if(de.StartSetc > sectors.Count)
                {
                        throw new CFException("Compound File is invalid");    
                }
	}
}

Sorry for my bad description about the issue.
Best regards,
Nhut M. Ngo

@salaros salaros added the bug label Feb 28, 2017
@bormm
Copy link

bormm commented Jul 26, 2017

@nmnhut2010 @salaros This project is a old fork of the original OpenMcdf source hosted on sourceforge. I would recommend using and improving the original now, after it also moved to github a while ago: (https://github.com/ironfede/openmcdf).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants