[Mapserver-dev] Change in maptree.c

Julien-Samuel Lacroix lacroix at dmsolutions.ca
Thu Jan 23 12:20:11 EST 2003


Hi,

I found a problem with the qix index parsing.  When the needswap flag is 
set and there's 4 or less shapes, there's no deep in the quadtree and 
needswap is set incorrectly.  So the line that check if the depth bytes 
are reversed becomes wrong because it check if the first 2 bytes are 0 
and it's always the case because all bytes are 0. Here's the line:

psTree->LSB_order = !(pabyBuf[4] == 0 && pabyBuf[5] == 0);
psTree->needswap = ((psTree->LSB_order) != (!bBigEndian));

In my case, there's no depth, so it set needswap at 1 but it should be 
zero.  From there, the number of shapes and the number of sub nodes are 
set to something like 60 000 000 and 134 000 000 instead of 4 and 0 so 
it goes in an infinit loop.  I propose this fix:

If there's no maxdepth, check the first 4 bytes (1,2,3,4) that must be 
the number of features (psTree->nShapes) and must not be greater than 
65535 (integer value) :

/* --------------------------------------------------------------- */
/* must check if the 2 first bytes equal 0 of max depth that cannot*/
/* be more than 65535. If yes, we must swap all value. The problem */
/* here is if there's no Depth (bite 5,6,7,8 in the file) all bytes*/
/* will be set to 0. So, we will test with the number of shapes (byte*/
/* 1,2,3,4) that cannot be more than 65535 too.                    */
/* --------------------------------------------------------------- */
      if((pabyBuf[4] == 0 && pabyBuf[5] == 0 &&
          pabyBuf[6] == 0 && pabyBuf[7] == 0))
      {
        psTree->LSB_order = !(pabyBuf[0] == 0 && pabyBuf[1] == 0);
      }
      else
      {
        psTree->LSB_order = !(pabyBuf[4] == 0 && pabyBuf[5] == 0);
      }
      psTree->needswap = ((psTree->LSB_order) != (!bBigEndian));


My questions are, Is this fix is compatible with other format of .qix 
files?  Is this fix okay with you? Frank? Steve?

I saw the parser check for a SQT signature, must we apply it there too?

Thanks
Julien







More information about the mapserver-dev mailing list