<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>15054</bug_id>
          
          <creation_ts>2007-08-22 16:54:52 -0700</creation_ts>
          <short_desc>Divide by 0 in AutoTableLayout::layout</short_desc>
          <delta_ts>2007-12-06 16:20:00 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tables</component>
          <version>523.x (Safari 3)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brett Wilson (Google)">brettw</reporter>
          <assigned_to name="Brett Wilson (Google)">brettw</assigned_to>
          <cc>koivisto</cc>
    
    <cc>mitz</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1676</commentid>
    <comment_count>0</comment_count>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2007-08-22 16:54:52 -0700</bug_when>
    <thetext>This is based on a crash dump, so I don&apos;t have repro steps. However, it looks like the code can produce divide by 0. Here&apos;s the code in question:

    // spread over the rest
    if (available &gt; 0 &amp;&amp; nEffCols &gt; numAutoEmptyCellsOnly) {
        int total = nEffCols - numAutoEmptyCellsOnly;
        // still have some width to spread
        int i = nEffCols;
        while (i--) {
            // variable columns with empty cells only don&apos;t get any width
            if (m_layoutStruct[i].width.isAuto() &amp;&amp;
                    m_layoutStruct[i].emptyCellsOnly)
                continue;
            int w = available / total;  &lt;&lt;&lt;&lt; divide by 0
            available -= w;
            total--;
            m_layoutStruct[i].calcWidth += w;
        }
    }

The crash/divide by 0 is in &quot;int w = available / total;&quot;

It looks like this crash will occur any time
  available &gt; 0, nEffCols &gt; numAutoEmptyCellsOnly, and
  numAutoEmptyCellsOnly &gt; 0 and nEffCols &gt; numAutoEmptyCellsOnly + 1
It appears that the common case is numAutoEmptyCellsOnly is 0, I did not see any other value in my testing, and I don&apos;t know how to get this value to be different. Maybe somebody familiar with table layout can produce a testcase.

For example, if nEffCols = 3, numAutoEmptyCellsOnly = 1:
We will get:
  i = 3
  total = 2
The first time through the loop:
  i will be changed from 3 to 2
  total --    means total = 1
The second time through the loop:
  i will be changed from 2 to 1
  total -- means total = 0
The third time through the loop:
  i will be changed from 1 to 0
  w = available / total -&gt; DIVIDE BY 0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644</commentid>
    <comment_count>1</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2007-08-22 22:03:59 -0700</bug_when>
    <thetext>Marvin, could you please attach the crash log to this bug?  Thanks!

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1631</commentid>
    <comment_count>2</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2007-08-23 02:17:45 -0700</bug_when>
    <thetext>It is not immediatly obvious to me how you would get this crash. numAutoEmptyCellsOnly should be equal to amount of cases where (m_layoutStruct[i].width.isAuto() &amp;&amp; m_layoutStruct[i].emptyCellsOnly) == true. 

This crash should be reproducible. Could you find the page where it happened?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1338</commentid>
    <comment_count>3</comment_count>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2007-08-28 11:00:31 -0700</bug_when>
    <thetext>This crash is from my internal crash system, so it wouldn&apos;t be useful to you. I do not have a URL. Here is the not very exciting stack:

0x102b79ea      [autotablelayout.cpp:695]      WebCore::AutoTableLayout::layout()
0x102179ac      [rendertable.cpp:287]  WebCore::RenderTable::layout()
0x1026b9ec      [renderblock.cpp:1214]         WebCore::RenderBlock::layoutBlockChildren(bool)
0x1026f02a      [renderblock.cpp:585]  WebCore::RenderBlock::layoutBlock(bool)
0x102a80dc      [rendertablecell.cpp:135]      WebCore::RenderTableCell::layout()
0x102aa8ad      [rendertablerow.cpp:131]       WebCore::RenderTableRow::layout()
0x102b41c1      [rendercontainer.cpp:494]      WebCore::RenderContainer::layout()
0x10217a4e      [rendertable.cpp:299]  WebCore::RenderTable::layout()
0x1026b9ec      [renderblock.cpp:1214]         WebCore::RenderBlock::layoutBlockChildren(bool)
0x1026f02a      [renderblock.cpp:585]  WebCore::RenderBlock::layoutBlock(bool)
0x102647ca      [renderblock.cpp:494]  WebCore::RenderBlock::layout()
0x1026b9ec      [renderblock.cpp:1214]         WebCore::RenderBlock::layoutBlockChildren(bool)
0x1026f02a      [renderblock.cpp:585]  WebCore::RenderBlock::layoutBlock(bool)
0x102647ca      [renderblock.cpp:494]  WebCore::RenderBlock::layout()
0x1026b9ec      [renderblock.cpp:1214]         WebCore::RenderBlock::layoutBlockChildren(bool)
0x1026f02a      [renderblock.cpp:585]  WebCore::RenderBlock::layoutBlock(bool)
0x102647ca      [renderblock.cpp:494]  WebCore::RenderBlock::layout()
0x10210220      [renderview.cpp:111]   WebCore::RenderView::layout()
0x101d1915      [frameview.cpp:425]    WebCore::FrameView::layout(bool)
0x1023589a      [timer.h:96]   WebCore::Timer&lt;WebCore::PageCache&gt;::fired()
0x102056f8      [timer.cpp:336]        WebCore::TimerBase::fireTimers(double,WTF::Vector&lt;WebCore::TimerBase *,0&gt; const &amp;)

I will keep my eyes out for more crashes like this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1335</commentid>
    <comment_count>4</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2007-08-28 11:02:28 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; This crash is from my internal crash system, so it wouldn&apos;t be useful to you.

Maybe not, but an &quot;internal crash system&quot; certainly sounds useful!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63531</commentid>
    <comment_count>5</comment_count>
      <attachid>17760</attachid>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2007-12-06 14:35:11 -0800</bug_when>
    <thetext>Created attachment 17760
Reduced test case

Here are the requirements for the crash to occur in AutoTableLayout::layout():

* The width of the table must be not evenly divisible by the number of nonempty
columns such that there is a remainder of 1 when you get to the block commented
&quot;// spread over the rest&quot;.

* There must be a nonempty column, as well as an empty column with a fixed
width, and there must be a row with colspan covering both of them.

* When this bug is triggered, the empty column will get a width of type &quot;fixed&quot;
and a number, and the effective width will be 0 (Auto). If you remove the
colspan, the effective width will be the same as the width.

* The setting of the effWidth to the width happens at the top of
AutoTableLayout::calcEffectiveWidth. In the case of this bug, it is reset to
zero on the line &quot;m_layoutStruct[pos].effWidth = Length();&quot;

The bug occurs because when the number of fixed, relative, etc. columns is
computed near the top of layout(), it uses effWidth, but in the &quot;rest&quot; clause,
it uses &quot;width&quot;. I think this is just a one line fix to use &quot;effWidth&quot; below.

I will put a patch together.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63536</commentid>
    <comment_count>6</comment_count>
    <who name="">mitz</who>
    <bug_when>2007-12-06 14:52:44 -0800</bug_when>
    <thetext>I am sorry, this is &lt;rdar://problem/5612459&gt; which has recently been fixed in &lt;http://trac.webkit.org/projects/webkit/changeset/28118&gt;. I did not realize that it was the same as this bug. Please verify and close if you agree.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63545</commentid>
    <comment_count>7</comment_count>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2007-12-06 16:20:00 -0800</bug_when>
    <thetext>Wow, I wasted a long time :(</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>17760</attachid>
            <date>2007-12-06 14:35:11 -0800</date>
            <delta_ts>2007-12-06 14:35:11 -0800</delta_ts>
            <desc>Reduced test case</desc>
            <filename>reduced.html</filename>
            <type>text/html</type>
            <size>269</size>
            <attacher name="Brett Wilson (Google)">brettw</attacher>
            
              <data encoding="base64">PHRhYmxlIGNlbGxzcGFjaW5nPTAgY2VsbHBhZGRpbmc9MCBzdHlsZT0id2lkdGg6NzU5cHg7Ij48
dHI+DQogIDx0ZD48L3RkPg0KICA8dGQ+PC90ZD4NCiAgPHRkIHdpZHRoPSIxMCUiPjwvdGQ+DQo8
L3RyPjx0cj4NCiAgPHRkIHdpZHRoPSI5MCUiPkhlbGxvPC90ZD4NCiAgPHRkIHN0eWxlPXdpZHRo
OjE1cHg7Ij48L3RkPg0KICA8dGQ+PC90ZD4NCjwvdHI+PHRyPg0KICA8dGQgY29sc3Bhbj0iMyIg
c3R5bGU9IndpZHRoOjEwMCU7Ij48L3RkPg0KPC90cj48dGFibGU+DQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>