private static StructuredStorageInterface.IPropertyStorage GetPropertyStorage(StructuredStorageInterface.IStorage iStorage, Guid propertySetGuid) { StructuredStorageInterface.IPropertySetStorage iPropertySetStorage = (StructuredStorageInterface.IPropertySetStorage) iStorage; if (null == iPropertySetStorage) { ComObjectGovernor.ReleaseObject(iStorage); return null; } try { return iPropertySetStorage.Open(ref propertySetGuid, Convert.ToInt32(StructuredStorageInterface.ReadOnlyMode)); } catch (System.Runtime.InteropServices.COMException e) { ComObjectGovernor.ReleaseObject(iStorage); uint errorCode = (uint) e.ErrorCode; if (errorCode == StructuredStorageInterface.STG_E_FILENOTFOUND) { return null; } // VE2163: Outlook crash sending Excel document created with eCopy if (errorCode == StructuredStorageInterface.STG_E_INVALIDHEADER) { string err = "Detected corruption in OLE Compound document (STG_E_INVALIDHEADER) when trying to retrieve PropertySet GUID=" + propertySetGuid; Logger.LogError(err); return null; } throw e; } }
private IStream GetStream(out StructuredStorageInterface.IStorage iStorage, string streamname) { if (m_bNotAStreamFile) { iStorage = null; return null; } if (!HasStructuredStorageHeader()) { m_bNotAStreamFile = false; iStorage = null; return null; } uint iRet = 0; if (Workshare.Interop.Options.OptionApi.GetBool("UseDiskBasedFiles") && !string.IsNullOrEmpty(m_fileData.Filename) && m_fileData.BinaryFileData is DiskBinaryData) { iRet = StructuredStorageInterface.StgOpenStorage(m_fileData.Filename, null, StructuredStorageInterface.ReadOnlyModeTransacted, System.IntPtr.Zero, 0, out iStorage); } else { if (m_lockbyteswrapper == null) { m_lockbyteswrapper = new LockBytesWrapper(m_fileData.BinaryFileData); } else { if (!m_lockbyteswrapper.Represents(m_fileData.BinaryFileData)) { throw new InvalidOperationException("Invalid use of lockbyteswrapper in FileTypeIdentifiers"); } } if (null == m_lockbyteswrapper.ILockBytesInterface) { ErrorMessage errorMessage = new ErrorMessage( "EXPECTED_VALID", "Workshare.Policy.Engine.Properties", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new NullReferenceException(errorMessage.DisplayString + " - " + "ILockBytes"); } iRet = StructuredStorageInterface.StgOpenStorageOnILockBytes(m_lockbyteswrapper.ILockBytesInterface, null, StructuredStorageInterface.ReadOnlyMode, System.IntPtr.Zero, 0, out iStorage); } if (0 != iRet) { ComObjectGovernor.ReleaseObject(iStorage); if (StructuredStorageInterface.STG_E_SHAREVIOLATION != iRet) { m_bNotAStreamFile = true; return null; } ErrorMessage errorMessage = new ErrorMessage( "FAILED_OPEN_STORAGE", "Workshare.Policy.Engine.Properties", Assembly.GetExecutingAssembly(), iRet.ToString("x", CultureInfo.InvariantCulture)); Logger.LogError(errorMessage.LogString); throw new FileLoadException(errorMessage.DisplayString, m_fileData.Filename); } IStream iStream; try { iStream = iStorage.OpenStream(streamname, IntPtr.Zero, Convert.ToInt32(StructuredStorageInterface.ReadOnlyMode), 0); } catch (System.Runtime.InteropServices.COMException) { ComObjectGovernor.ReleaseObject(iStorage); // iStorage.OpenStream no longer throws STG_E_FILENOTFOUND for some reason, and instead throws an RPC error // which is quite generic anyway ... so we no longer check for error code. //if (StructuredStorageInterface.STG_E_FILENOTFOUND != (uint) e.ErrorCode) //throw e; return null; } return iStream; }