Boost C++ Libraries: Ticket #5881: BGL isomorphism: off-by-one error in isomorphism.hpp https://svn.boost.org/trac10/ticket/5881 <p> While in test_isomorphism() when creating a multiplicity vector, the vector is possibly indexed with max_invariant while it's max index is max_invariant-1. </p> <p> The code in question is: </p> <div class="wiki-code"><div class="code"><pre><span class="mi">154</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">size_type</span><span class="o">&gt;</span> <span class="n">multiplicity</span><span class="p">(</span><span class="n">max_invariant</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="mi">155</span> <span class="nf">BGL_FORALL_VERTICES_T</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">G1</span><span class="p">,</span> <span class="n">Graph1</span><span class="p">)</span> <span class="mi">156</span> <span class="o">++</span><span class="n">multiplicity</span><span class="p">[</span><span class="n">invariant1</span><span class="p">(</span><span class="n">v</span><span class="p">)];</span> </pre></div></div><p> Simple fix for this is to change the line 154 to: </p> <div class="wiki-code"><div class="code"><pre><span class="mi">154</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">size_type</span><span class="o">&gt;</span> <span class="n">multiplicity</span><span class="p">(</span><span class="n">max_invariant</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5881 Trac 1.4.3 Jeremiah Willcock Fri, 09 Sep 2011 15:36:20 GMT <link>https://svn.boost.org/trac10/ticket/5881#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5881#comment:1</guid> <description> <p> This code appears to be correct using the definition of <code>max_invariant</code> in the documentation. Is the test case incorrect, or do you think <code>isomorphism</code> itself is incorrect? </p> </description> <category>Ticket</category> </item> <item> <author>Esa Määttä <esa.maatta@…></author> <pubDate>Sat, 10 Sep 2011 10:56:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5881#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5881#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5881#comment:1" title="Comment 1">jewillco</a>: </p> <blockquote class="citation"> <p> This code appears to be correct using the definition of <code>max_invariant</code> in the documentation. Is the test case incorrect, or do you think <code>isomorphism</code> itself is incorrect? </p> </blockquote> <p> You can test it by changing the indexing of the multiplicity vector to .at() and with a simple two node graph: </p> <pre class="wiki">digraph G { 0; 1; 0-&gt;1 ; 1-&gt;1 ; } </pre><p> And with code like this: </p> <div class="wiki-code"><div class="code"><pre><span class="mi">154</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">size_type</span><span class="o">&gt;</span> <span class="n">multiplicity</span><span class="p">(</span><span class="n">max_invariant</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="mi">155</span> <span class="nf">BGL_FORALL_VERTICES_T</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">G1</span><span class="p">,</span> <span class="n">Graph1</span><span class="p">)</span> <span class="p">{</span> <span class="mi">156</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;v: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">v</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;, &quot;</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;invariant(v): &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">invariant1</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="mi">157</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;, max_invariant: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">max_invariant</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="mi">158</span> <span class="o">++</span><span class="n">multiplicity</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="n">invariant1</span><span class="p">(</span><span class="n">v</span><span class="p">));</span> <span class="mi">159</span> <span class="p">}</span> </pre></div></div><p> The output for me is: </p> <pre class="wiki">v: 0, invariant(v): 3, max_invariant: 5 v: 1, invariant(v): 5, max_invariant: 5 terminate called without an active exception Aborted </pre> </description> <category>Ticket</category> </item> <item> <author>Esa Määttä <esa.maatta@…></author> <pubDate>Sat, 10 Sep 2011 11:24:49 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5881 https://svn.boost.org/trac10/ticket/5881 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">gdb_efence_where.log</span> </li> </ul> <p> Log of gdb where command, when a program is compiled with efence. Indexing multiplicty vector causes segfault at /usr/include/boost/graph/isomorphism.hpp:156 </p> Ticket Jeremiah Willcock Sat, 10 Sep 2011 17:48:08 GMT <link>https://svn.boost.org/trac10/ticket/5881#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5881#comment:3</guid> <description> <p> I ran a variant of the Boost.Graph <code>isomorphism</code> test with your graph and the replacement with <code>.at()</code> done, and nothing failed. This was with the trunk version of Boost. Is your code passing in custom invariant maps or a custom <code>max_invariant</code> value? </p> </description> <category>Ticket</category> </item> <item> <author>Esa Määttä <esa.maatta@…></author> <pubDate>Sun, 11 Sep 2011 07:33:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5881#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5881#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5881#comment:3" title="Comment 3">jewillco</a>: </p> <blockquote class="citation"> <p> I ran a variant of the Boost.Graph <code>isomorphism</code> test with your graph and the replacement with <code>.at()</code> done, and nothing failed. This was with the trunk version of Boost. Is your code passing in custom invariant maps or a custom <code>max_invariant</code> value? </p> </blockquote> <p> Nope, I'm just calling the isomorphism algorithm like in some examples: <br /> </p> <p> isomorphism(g1, g2, isomorphism_map(..)) </p> <p> So the problem is probably in how I define the Graph type or initialize it. Here's the Graph type I use: </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// Define internal vertex properties</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">vertex_color_t</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">default_color_type</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">vertex_index_t</span><span class="p">,</span> <span class="kt">int</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">vertex_degree_t</span><span class="p">,</span> <span class="kt">int</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">vertex_in_degree_t</span><span class="p">,</span> <span class="kt">int</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">vertex_out_degree_t</span><span class="p">,</span> <span class="kt">int</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="o">&gt;</span> <span class="o">&gt;</span> <span class="o">&gt;</span> <span class="n">VertexProperties</span><span class="p">;</span> <span class="c1">// Define used edge properties </span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">edge_color_t</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">default_color_type</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">property</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">edge_index_t</span><span class="p">,</span> <span class="kt">int</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="n">EdgeProperties</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">adjacency_list</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">listS</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">vecS</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">bidirectionalS</span><span class="p">,</span> <span class="n">VertexProperties</span><span class="p">,</span> <span class="n">EdgeProperties</span><span class="o">&gt;</span> <span class="n">Graph</span><span class="p">;</span> </pre></div></div><p> If above doesn't help I'll try to construct a simple test case when I have time. Also I'm using 1.47.0, haven't yet tested with trunk. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jeremiah Willcock</dc:creator> <pubDate>Mon, 12 Sep 2011 15:07:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5881#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5881#comment:5</guid> <description> <p> I think you will need to create a test case, or at least put your entire call to <code>isomorphism</code>. </p> </description> <category>Ticket</category> </item> <item> <author>bastianra@…</author> <pubDate>Fri, 28 Oct 2011 15:58:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5881#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5881#comment:6</guid> <description> <p> I am experiencing the same issue. To me it seems the problem lies in the implementation of degree_vertex_invariant (starting at line 299 in trunk): </p> <pre class="wiki"> size_type operator()(vertex_t v) const { return (m_max_vertex_in_degree + 1) * out_degree(v, m_g) + get(m_in_degree_map, v); } // The largest possible vertex invariant number size_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (m_max_vertex_in_degree + 2) * m_max_vertex_out_degree + 1; } </pre><p> consider a vertex with in_degree==10 and out_degree==1, and assume both are the maximum values. operator() will return (10+1)*1+10, i.e. 21, however the value of max is (10+2)*1+1 i.e. 13. </p> <p> replacing max with </p> <pre class="wiki"> size_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (m_max_vertex_in_degree + 1) * m_max_vertex_out_degree + m_max_vertex_in_degree + 1; } </pre><p> resolved the issue <strong>(tested only in 1_47_0 with a few of my own graphs, not tested in trunk)</strong>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jeremiah Willcock</dc:creator> <pubDate>Sat, 29 Oct 2011 06:11:05 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5881#comment:7 https://svn.boost.org/trac10/ticket/5881#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/75165" title="Fixed degree_vertex_invariant::max; fixes #5881">[75165]</a>) Fixed degree_vertex_invariant::max; fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5881" title="#5881: Bugs: BGL isomorphism: off-by-one error in isomorphism.hpp (closed: fixed)">#5881</a> </p> Ticket