Untrusted files
editThe reader checks every structure it reads: the checksums of the pages and the blocks, the bounds of the references and the levels of the trees. It reports a malformed file with an InvalidEmailDataException, and a feature it does not support with an UnsupportedEmailFeatureException. Both derive from EmailException.
Limits
PstReadOptions limits the memory and the time a file can use: the size of a value loaded in memory, the depth of the trees and of the embedded messages, and the number of pages and blocks kept in a cache. A file that exceeds them throws an EmailResourceLimitException:
var options = new PstReadOptions
{
MaxPropertySize = 16 * 1024 * 1024,
MaxEmbeddedMessageDepth = 4,
};
try
{
using var file = PstFile.Open(path, options);
Assert.NotEmpty(file.RootFolder.Folders);
}
catch (EmailException)
{
// InvalidEmailDataException, EmailResourceLimitException or UnsupportedEmailFeatureException
}The content of an attachment read with OpenRead is not limited: it is read block by block.
Checking a file
PstFile.Validate checks the whole file without stopping at the first problem: the header, the B-trees, every block and every node, the heaps and the tables, and the allocation maps. It returns the problems it finds:
using var file = PstFile.Open(path);
var issues = file.Validate();
Assert.Empty(issues);VerifyChecksums turns off the checksums, to read what a damaged file still contains.