Return-Path: X-Original-To: apmail-logging-log4net-dev-archive@www.apache.org Delivered-To: apmail-logging-log4net-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 141D0DDE0 for ; Mon, 5 Nov 2012 23:18:13 +0000 (UTC) Received: (qmail 12057 invoked by uid 500); 5 Nov 2012 23:18:12 -0000 Delivered-To: apmail-logging-log4net-dev-archive@logging.apache.org Received: (qmail 12013 invoked by uid 500); 5 Nov 2012 23:18:12 -0000 Mailing-List: contact log4net-dev-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET Dev" List-Id: Delivered-To: mailing list log4net-dev@logging.apache.org Received: (qmail 11830 invoked by uid 99); 5 Nov 2012 23:18:12 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2012 23:18:12 +0000 Date: Mon, 5 Nov 2012 23:18:12 +0000 (UTC) From: "Michael Cessna (JIRA)" To: log4net-dev@logging.apache.org Message-ID: <1520999476.71157.1352157492506.JavaMail.jiratomcat@arcas> In-Reply-To: <188977097.69660.1352139612190.JavaMail.jiratomcat@arcas> Subject: [jira] [Updated] (LOG4NET-360) EventLogAppender can corrupt the event log on Windows Vista and higher if the string is longer than 31839 bytes MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LOG4NET-360?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Michael Cessna updated LOG4NET-360: ----------------------------------- Attachment: Event Log Corruption.txt This file shows the stack from an exception that was the result of a System.ComponentModel.Win32Exception with the message "The event log file is corrupted" after calling EventLog.WriteEntry() with a string 31,876 bytes long under Windows 7. Note: The error won't happen all of the time, but corruption will eventually occur. > EventLogAppender can corrupt the event log on Windows Vista and higher if the string is longer than 31839 bytes > --------------------------------------------------------------------------------------------------------------- > > Key: LOG4NET-360 > URL: https://issues.apache.org/jira/browse/LOG4NET-360 > Project: Log4net > Issue Type: Bug > Components: Appenders > Affects Versions: 1.2.11 > Environment: Windows Vista or higher > Reporter: Michael Cessna > Priority: Blocker > Attachments: Event Log Corruption.txt > > > private const int MaxEventLogMsgLength_PreVista = 32766; > private const int MaxEventLogMsgLength_VistaOrHigher = 31839; > /// > /// Gets the maximum allowable size of event log message for the current operating system. > /// > /// > public static int GetMaxEventLogMessageSize() > { > // http://msdn.microsoft.com/en-us/library/xzwc042w(v=vs.100).aspx > // The 32766 documented max size is two bytes shy of 32K (I'm assuming 32766 may leave space for a two byte null > // terminator of #0#0). The 32766 max length is what the .NET 4.0 source code checks for, but this is WRONG!... > // strings with a length > 31839 on Windows Vista or higher can CORRUPT the event log! See: > // System.Diagnostics.EventLogInternal.InternalWriteEvent() for the use of the 32766 max size. > var maxEventMsgSize = MaxEventLogMsgLength_PreVista; > // Windows Vista and higher > if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6) > { > // See ReportEvent API: http://msdn.microsoft.com/en-us/library/aa363679(VS.85).aspx > // ReportEvent's lpStrings parameter: "A pointer to a buffer containing an array of null-terminated strings that are > // merged into the message before Event Viewer displays the string to the user. This parameter must be a valid pointer > // (or NULL), even if wNumStrings is zero. Each string is limited to 31,839 characters." > // Going beyond the size of 31839 will (at some point) corrupt the event log on Windows Vista or higher! It may succeed > // for a while...but you will eventually run into the error: "System.ComponentModel.Win32Exception : A device attached to > // the system is not functioning", and the event log will then be corrupt (I was able to corrupt an event log using a > // length of 31877 on Windows 7). > // The max size for Windows Vista or higher is documented here: http://msdn.microsoft.com/en-us/library/xzwc042w(v=vs.100).aspx. > // Going over this size may succeed a few times but the buffer will overrun and eventually corrupt the log (based on testing). > // Log4net's own EventLogAppender will write up to 32000 bytes (0x7D00), which can corrupt the event log. > // The maxEventMsgSize size is based on the max buffer size of the lpStrings parameter of the ReportEvent API. > // The documented max size for EventLog.WriteEntry for Windows Vista and higher is 31839, but I'm leaving room for a > // terminator of #0#0, as we cannot see the source of ReportEvent (though we could use an API monitor to examine the > // buffer, given enough time). > // TODO: Use an API monitor to examine how the ReportEvent API allocates a buffer for the event log message strings. > const int terminatorLength = 2; // Safety for now. > maxEventMsgSize = MaxEventLogMsgLength_VistaOrHigher - terminatorLength; > } > return maxEventMsgSize; > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira