/ Check-in [c0bf3ff3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Stricter enforcement of the JSON and GeoJSON standards in the Geopoly extension.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c0bf3ff3af4d34ef7801c16e39128e894b00699313f4915f57aa73b57642f7fd
User & Date: drh 2018-08-28 19:23:41
Context
2018-08-28
21:12
Disable the server1.test script on old PPC Macs due to problems in the pthreads implementation on those archaic machines. check-in: 43efdd8c user: drh tags: trunk
19:23
Stricter enforcement of the JSON and GeoJSON standards in the Geopoly extension. check-in: c0bf3ff3 user: drh tags: trunk
15:51
Fix new issues in the geopoly module discovered by TH3. check-in: 22fff9af user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/geopoly.c.

   144    144   
   145    145   /* Parse out a number.  Write the value into *pVal if pVal!=0.
   146    146   ** return non-zero on success and zero if the next token is not a number.
   147    147   */
   148    148   static int geopolyParseNumber(GeoParse *p, GeoCoord *pVal){
   149    149     char c = geopolySkipSpace(p);
   150    150     const unsigned char *z = p->z;
   151         -  int j;
          151  +  int j = 0;
   152    152     int seenDP = 0;
   153    153     int seenE = 0;
   154         -  assert( '-' < '0' );
   155         -  if( c<='0' ){
   156         -    j = c=='-';
   157         -    if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return 0;
          154  +  if( c=='-' ){
          155  +    j = 1;
          156  +    c = z[j];
   158    157     }
   159         -  j = 1;
          158  +  if( c=='0' && z[j+1]>='0' && z[j+1]<='9' ) return 0;
   160    159     for(;; j++){
   161    160       c = z[j];
   162    161       if( c>='0' && c<='9' ) continue;
   163    162       if( c=='.' ){
   164    163         if( z[j-1]=='-' ) return 0;
   165    164         if( seenDP ) return 0;
   166    165         seenDP = 1;
................................................................................
   231    230           s.z++;
   232    231           continue;
   233    232         }
   234    233         break;
   235    234       }
   236    235       if( geopolySkipSpace(&s)==']'
   237    236        && s.nVertex>=4
          237  +     && s.a[0]==s.a[s.nVertex*2-2]
          238  +     && s.a[1]==s.a[s.nVertex*2-1]
   238    239        && (s.z++, geopolySkipSpace(&s)==0)
   239    240       ){
   240    241         int nByte;
   241    242         GeoPoly *pOut;
   242         -      int x = (s.nVertex-1)*2;
   243         -      if( s.a[x]==s.a[0] && s.a[x+1]==s.a[1] ) s.nVertex--;
   244         -      nByte = sizeof(GeoPoly) * (s.nVertex-1)*2*sizeof(GeoCoord);
          243  +      int x = 1;
          244  +      s.nVertex--;  /* Remove the redundant vertex at the end */
          245  +      nByte = sizeof(GeoPoly) * s.nVertex*2*sizeof(GeoCoord);
   245    246         pOut = sqlite3_malloc64( nByte );
   246    247         x = 1;
   247    248         if( pOut==0 ) goto parse_json_err;
   248    249         pOut->nVertex = s.nVertex;
   249    250         memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
   250    251         pOut->hdr[0] = *(unsigned char*)&x;
   251    252         pOut->hdr[1] = (s.nVertex>>16)&0xff;
................................................................................
   303    304             p->hdr[0] ^= 1;
   304    305           }
   305    306         }
   306    307       }
   307    308       if( pRc ) *pRc = SQLITE_OK;
   308    309       return p;
   309    310     }else if( sqlite3_value_type(pVal)==SQLITE_TEXT ){
   310         -    return geopolyParseJson(sqlite3_value_text(pVal), pRc);
          311  +    const unsigned char *zJson = sqlite3_value_text(pVal);
          312  +    if( zJson==0 ){
          313  +      if( pRc ) *pRc = SQLITE_NOMEM;
          314  +      return 0;
          315  +    }
          316  +    return geopolyParseJson(zJson, pRc);
   311    317     }else{
   312    318       if( pRc ) *pRc = SQLITE_ERROR;
   313         -    if( pCtx!=0 ) sqlite3_result_error(pCtx, "not a valid polygon", -1);
   314    319       return 0;
   315    320     }
   316    321   }
   317    322   
   318    323   /*
   319    324   ** Implementation of the geopoly_blob(X) function.
   320    325   **