<div dir="ltr"><div>Hi!</div><div><br></div><div>While investigating NaN handling in GiST indexes I found two buggy checks gserialized_gist_compress_2d:</div><div><br></div><div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>/* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>if ( result == LW_FAILURE )</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>{</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>POSTGIS_DEBUG(4, "[GIST] empty geometry!");</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">             </span>PG_RETURN_POINTER(entry_in);</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>}</font></div></div><div><font face="courier new, monospace"><br></font></div><div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>/* Check all the dimensions for finite values */</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>if ( ! finite(bbox_out.xmax) || ! finite(bbox_out.xmin) ||</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>     ! finite(bbox_out.ymax) || ! finite(bbox_out.ymin) )</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">         </span>POSTGIS_DEBUG(4, "[GIST] infinite geometry!");</font></div>

<div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>PG_RETURN_POINTER(entry_in);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>}</font></div>

</div><div><br></div><div>On failure these checks return original GISTENTRY with geometry key. I don't understand what is it supposed to do, but what it's actually do is to interpret first 16 bytes of geometry as box3df. For sure, it leads to broken index key and invalid answers from index scan.</div>

<br clear="all"><div><span style="font-family:arial,sans-serif;font-size:13px">------</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">With best regards,</span><br style="font-family:arial,sans-serif;font-size:13px">

<span style="font-family:arial,sans-serif;font-size:13px">Alexander Korotkov.</span><br></div>
</div>