/***************** * protected methods */ /***************** * public methods */ //meant to avoid code repetition (is called from OTFontVal too) public bool ValidateTable(OTTable table, Validator v, DirectoryEntry de, OTFontVal fontOwner) { String tname = GetTableManager().GetUnaliasedTableName(de.tag); bool bRet = true; // verify the checksum value from the directory entry matches the checksum for the table if (!(tname == "DSIG" && IsCollection())) { uint calcChecksum = 0; if (table != null) { calcChecksum = table.CalcChecksum(); } if (de.checkSum != calcChecksum) { string s = "table '" + de.tag + "', calc: 0x" + calcChecksum.ToString("x8") + ", font: 0x" + de.checkSum.ToString("x8"); v.Error(T.T_NULL, E._DE_E_ChecksumError, de.tag, s); bRet = false; } } // verify that table has pad bytes set to zero if (table != null) { uint nBytes = 0; try { nBytes = GetNumPadBytesAfterTable(table); } catch (Exception e) { v.ApplicationError(T.T_NULL, E._Table_E_Exception, de.tag, "GetNumPadBytesAfterTable: " + e.Message); bRet = false; } bool bPadBytesZero = true; if (nBytes != 0) { long PadFilePos = table.GetBuffer().GetFilePos() + table.GetBuffer().GetLength(); byte[] padbuf = ReadBytes(PadFilePos, nBytes); for (int iByte = 0; iByte < padbuf.Length; iByte++) { if (padbuf[iByte] != 0) { bPadBytesZero = false; break; } } } if (bPadBytesZero == false) { v.Warning(T.T_NULL, W._DE_W_PadBytesNotZero, de.tag, "after " + de.tag + " table"); } } // ask the table object to validate its data if (!(tname == "DSIG" && IsCollection())) { v.OnTableValidationEvent(de, true); } if (table != null) { if (v.TestTable(de.tag)) // don't test deselected tables { try { ITableValidate valtable = (ITableValidate)table; bRet &= valtable.Validate(v, fontOwner); } catch (InvalidCastException e) { v.ApplicationError(T.T_NULL, E._Table_E_Exception, table.m_tag, e.ToString()); bRet = false; } } else { v.Info(I._Table_I_NotSelected, de.tag); } } else { if (de.length == 0) { // check if it's a known OT table type since zero length private tables seem allowable if (TableManager.IsKnownOTTableType(de.tag)) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The directory entry length is zero"); bRet = false; } } else if (de.offset == 0) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The directory entry offset is zero"); bRet = false; } else if (de.offset > GetFileLength()) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The table offset points past end of file"); bRet = false; } else if (de.offset + de.length > GetFileLength()) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The table extends past end of file"); bRet = false; } else { v.Error(E._Table_E_Invalid, de.tag); bRet = false; } } if (!(tname == "DSIG" && IsCollection())) { v.OnTableValidationEvent(de, false); } return(bRet); }
/***************** * protected methods */ /***************** * public methods */ //meant to avoid code repetition (is called from OTFontVal too) public bool ValidateTable(OTTable table, Validator v, DirectoryEntry de, OTFontVal fontOwner) { String tname = GetTableManager().GetUnaliasedTableName(de.tag); bool bRet = true; // verify the checksum value from the directory entry matches the checksum for the table if (!(tname == "DSIG" && IsCollection())) { uint calcChecksum = 0; if (table != null) { calcChecksum = table.CalcChecksum(); } if (de.checkSum != calcChecksum) { string s = "table '" + de.tag + "', calc: 0x" + calcChecksum.ToString("x8") + ", font: 0x" + de.checkSum.ToString("x8"); v.Error(T.T_NULL, E._DE_E_ChecksumError, de.tag, s); bRet = false; } } // verify that table has pad bytes set to zero if (table != null) { uint nBytes = GetNumPadBytesAfterTable(table); bool bPadBytesZero = true; if (nBytes != 0) { long PadFilePos = table.GetBuffer().GetFilePos() + table.GetBuffer().GetLength(); byte[] padbuf = ReadBytes(PadFilePos, nBytes); for (int iByte = 0; iByte < padbuf.Length; iByte++) { if (padbuf[iByte] != 0) { bPadBytesZero = false; break; } } } if (bPadBytesZero == false) { v.Warning(T.T_NULL, W._DE_W_PadBytesNotZero, de.tag, "after " + de.tag + " table"); } } // ask the table object to validate its data if (!(tname == "DSIG" && IsCollection())) v.OnTableValidationEvent(de, true); if (table != null) { if (v.TestTable(de.tag)) // don't test deselected tables { try { ITableValidate valtable = (ITableValidate)table; bRet &= valtable.Validate(v, fontOwner); } catch (InvalidCastException e) { v.ApplicationError(T.T_NULL, E._Table_E_Exception, table.m_tag, e.ToString()); bRet = false; } } else { v.Info(I._Table_I_NotSelected, de.tag); } } else { if (de.length == 0) { // check if it's a known OT table type since zero length private tables seem allowable if (TableManager.IsKnownOTTableType(de.tag)) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The directory entry length is zero"); bRet = false; } } else if (de.offset == 0) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The directory entry offset is zero"); bRet = false; } else if (de.offset > GetFileLength()) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The table offset points past end of file"); bRet = false; } else if (de.offset + de.length > GetFileLength()) { v.Error(T.T_NULL, E._Table_E_Invalid, de.tag, "The table extends past end of file"); bRet = false; } else { v.Error(E._Table_E_Invalid, de.tag); bRet = false; } } if (!(tname == "DSIG" && IsCollection())) v.OnTableValidationEvent(de, false); return bRet; }