<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Integer Overflow and operator::new</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx</link><description>As Raymond Chen pointed out last year ( http://blogs.msdn.com/oldnewthing/archive/2004/01/29/64389.aspx ), there is a potential integer overflow when calling operator::new. The C++ compiler in Visual Studio 2005 automatically generates defensive code</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Integer Overflow and operator::new</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#500917</link><pubDate>Wed, 07 Dec 2005 13:08:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:500917</guid><dc:creator>Alexei Zakharov</dc:creator><description>Is there any rational reason to use plain arrays in today’s C++ code?  Even if there wasn’t any possibility of integer overflow there are so many factors against C++ arrays (like type safety, exception safety to name a few) and so many proper abstraction classes developed to substitute arrays in C++ that there is no excuse to use plain vanilla C++ arrays in your code anymore.  The simplest suitable general purpose substitute is std::vector.  It’s been a part of the standard for 7 years.  It’s just a shame not to know about it and not to advocate its use instead of arrays.  It’s got neither problems listed above nor the integer overflow problem.  The bottom line is you can enhance the compiler to protect you from the unsafe C++ constructs (C legacy really), but at the end of the day they are still inherently unsafe and dangerous and your code is still vulnerable.  It’s just not the way to go with this language.  Better, safer, higher level abstractions is the way to go.  The language provides you with the tools you need to build them, and it also provides an excellent standard library that already has many abstractions you need.</description></item><item><title>re: Integer Overflow and operator::new</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#502816</link><pubDate>Mon, 12 Dec 2005 21:43:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:502816</guid><dc:creator>mTIE</dc:creator><description>So why not put an overflow check inside the implementation of new[]()??&lt;br&gt;&lt;br&gt;I would argue that if new CFoo[(1&amp;lt;&amp;lt;31)+1] runs a pointer to an array of [1] allocated object, that's a bug in new, and should be fixed in the RTL.</description></item><item><title>re: Integer Overflow and operator::new</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#507705</link><pubDate>Wed, 28 Dec 2005 14:37:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:507705</guid><dc:creator>Peter</dc:creator><description>The mul instruction is the slowest way to multiply the number by 4. You can get the same result faster with LEA edx, [edx * 4] or with SHL edx, 2 or with ADD edx, edx / ADD edx, edx&lt;br&gt;&lt;br&gt;What was optimization switches (/O1, /O2) when you compiled this code?</description></item><item><title>re: Integer Overflow and operator::new</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#509422</link><pubDate>Thu, 05 Jan 2006 02:33:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:509422</guid><dc:creator>Albatross</dc:creator><description>The new operation compiler &amp;quot;last chance&amp;quot; security protection is OK.&lt;br&gt;&lt;br&gt;However, I think a clarification on the usage of the MAX_FOO_ALLOWED upper layer protection proposed is necessary.&lt;br&gt;&lt;br&gt;The nature of the &amp;quot;integer overflow&amp;quot; scenario is because of the implicit sizeof multiplication that the new operator will execute, for such reason MAX_FOO_ALLOWED must be calculated based on that.&lt;br&gt;&lt;br&gt;#define MAX_CPUREG_VALUE (2^CPUBITS)&lt;br&gt;&lt;br&gt;#define MAX_FOO_ALLOWED &lt;br&gt;        (MAX_CPUREG_VALUE / sizeof(CFoo))&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Integer Overflow and operator::new</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#509423</link><pubDate>Thu, 05 Jan 2006 02:34:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:509423</guid><dc:creator>Albatross</dc:creator><description>The new operation compiler &amp;quot;last chance&amp;quot; security protection is OK.&lt;br&gt;&lt;br&gt;However, I think a clarification on the usage of the MAX_FOO_ALLOWED upper layer protection proposed is necessary.&lt;br&gt;&lt;br&gt;The nature of the &amp;quot;integer overflow&amp;quot; scenario is because of the implicit sizeof multiplication that the new operator will execute, for such reason MAX_FOO_ALLOWED must be calculated based on that.&lt;br&gt;&lt;br&gt;#define MAX_CPUREG_VALUE (2^CPUBITS)&lt;br&gt;&lt;br&gt;#define MAX_FOO_ALLOWED &lt;br&gt;        (MAX_CPUREG_VALUE / sizeof(CFoo))&lt;br&gt;&lt;br&gt;</description></item><item><title>Dean - Integer Overflows: The Next Big Thing</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#617832</link><pubDate>Mon, 05 Jun 2006 14:03:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:617832</guid><dc:creator>Dean - Integer Overflows: The Next Big Thing</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://codeka.com/blogs/index.php/dean/2006/06/05/integer_overflows_the_next_big_thing"&gt;http://codeka.com/blogs/index.php/dean/2006/06/05/integer_overflows_the_next_big_thing&lt;/a&gt;</description></item><item><title>Why Windows Vista is unaffected by the VML Bug</title><link>http://blogs.msdn.com/michael_howard/archive/2005/12/06/500629.aspx#1448476</link><pubDate>Thu, 11 Jan 2007 06:47:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1448476</guid><dc:creator>Michael Howard's Web Log</dc:creator><description>&lt;p&gt;MS07-004 does not affect Windows Vista, even though the coding bug is there. Why? The bug is an integer&lt;/p&gt;
</description></item></channel></rss>