Fix new issues in the geopoly module discovered by TH3.

FossilOrigin-Name: 22fff9afc2fb20906173f258aa8feae9b52acc69a0ca7baf4e914d29c4279a23
This commit is contained in:
drh 2018-08-28 15:51:10 +00:00
parent f5778751f7
commit 79931a1517
3 changed files with 26 additions and 17 deletions

View File

@ -187,9 +187,10 @@ static int geopolyParseNumber(GeoParse *p, GeoCoord *pVal){
}
/*
** If the input is a well-formed JSON array of coordinates, where each
** coordinate is itself a two-value array, then convert the JSON into
** a GeoPoly object and return a pointer to that object.
** If the input is a well-formed JSON array of coordinates with at least
** four coordinates and where each coordinate is itself a two-value array,
** then convert the JSON into a GeoPoly object and return a pointer to
** that object.
**
** If any error occurs, return NULL.
*/
@ -221,7 +222,7 @@ static GeoPoly *geopolyParseJson(const unsigned char *z, int *pRc){
c = geopolySkipSpace(&s);
s.z++;
if( c==',' ) continue;
if( c==']' ) break;
if( c==']' && ii>=2 ) break;
s.nErr++;
rc = SQLITE_ERROR;
goto parse_json_err;
@ -232,7 +233,10 @@ static GeoPoly *geopolyParseJson(const unsigned char *z, int *pRc){
}
break;
}
if( geopolySkipSpace(&s)==']' && s.nVertex>=4 ){
if( geopolySkipSpace(&s)==']'
&& s.nVertex>=4
&& (s.z++, geopolySkipSpace(&s)==0)
){
int nByte;
GeoPoly *pOut;
int x = (s.nVertex-1)*2;
@ -305,7 +309,7 @@ static GeoPoly *geopolyFuncParam(
}else if( sqlite3_value_type(pVal)==SQLITE_TEXT ){
return geopolyParseJson(sqlite3_value_text(pVal), pRc);
}else{
*pRc = SQLITE_ERROR;
if( pRc ) *pRc = SQLITE_ERROR;
if( pCtx!=0 ) sqlite3_result_error(pCtx, "not a valid polygon", -1);
return 0;
}
@ -1173,7 +1177,7 @@ static int geopolyFilter(
assert( argc==1 );
geopolyBBox(0, argv[0], bbox, &rc);
if( rc ){
return rc;
goto geopoly_filter_end;
}
pCsr->aConstraint = p = sqlite3_malloc(sizeof(RtreeConstraint)*4);
pCsr->nConstraint = 4;
@ -1222,7 +1226,10 @@ static int geopolyFilter(
if( rc==SQLITE_OK ){
RtreeSearchPoint *pNew;
pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
if( pNew==0 ) return SQLITE_NOMEM;
if( pNew==0 ){
rc = SQLITE_NOMEM;
goto geopoly_filter_end;
}
pNew->id = 1;
pNew->iCell = 0;
pNew->eWithin = PARTLY_WITHIN;
@ -1234,6 +1241,7 @@ static int geopolyFilter(
}
}
geopoly_filter_end:
nodeRelease(pRtree, pRoot);
rtreeRelease(pRtree);
return rc;
@ -1402,7 +1410,7 @@ static int geopolyUpdate(
pVtab->zErrMsg =
sqlite3_mprintf("_shape does not contain a valid polygon");
}
return rc;
goto geopoly_update_end;
}
coordChange = 1;
@ -1472,6 +1480,7 @@ static int geopolyUpdate(
}
}
geopoly_update_end:
rtreeRelease(pRtree);
return rc;
}

View File

@ -1,5 +1,5 @@
C Fix\sa\sproblem\scausing\sspurious\sSQLITE_CORRUPT\serrors\swhen\susing\sthe\ssnapshot\nAPI\sto\sread\sfrom\sold\sdatabase\ssnapshots.
D 2018-08-28T11:23:52.641
C Fix\snew\sissues\sin\sthe\sgeopoly\smodule\sdiscovered\sby\sTH3.
D 2018-08-28T15:51:10.106
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in d06f463c5b623a61ac27f5cb8214fca9e53a6704d34d6b8f2124e2b1b293c88f
@ -359,7 +359,7 @@ F ext/repair/test/checkfreelist01.test 3e8aa6aeb4007680c94a8d07b41c339aa635cc782
F ext/repair/test/checkindex01.test 6945d0ffc0c1dc993b2ce88036b26e0f5d6fcc65da70fc9df27c2647bb358b0f
F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
F ext/rtree/geopoly.c 01343c633cf59893abc0797571dbfe50d116a6474743941ba46b09ad085df271
F ext/rtree/geopoly.c 00e0cc341affcf65afd3449ce71ec45de106463e9d98b3248509e2c9499e50c8
F ext/rtree/rtree.c f3c2f1b5eea75b98d4d3dcdec2ebf2a69c036b53f2f3d196e61bf5016298255f
F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
F ext/rtree/rtree1.test 309afc04d4287542b2cd74f933296832cc681c7b014d9405cb329b62053a5349
@ -1758,7 +1758,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 666133e32ca8e95807f8437dc8401bc93e2e6508ab8e6ae1e6031b7cee1584ae
R 64c8500a3b3b1576c0a05df68a2057d2
U dan
Z 4febad62a4c0de1b34fab12b530aa165
P 535155be584ad8c1836e6b1c62de836d9872056d39608c995221c928cb5b365d
R 89e303590eb89c7b3ebe8848db3ad489
U drh
Z 6ec3cd71799cdaf9a300185233e89b80

View File

@ -1 +1 @@
535155be584ad8c1836e6b1c62de836d9872056d39608c995221c928cb5b365d
22fff9afc2fb20906173f258aa8feae9b52acc69a0ca7baf4e914d29c4279a23