Skip to content
Permalink
Browse files

Fix WMTS exception on out of range tile requests (#153)

  • Loading branch information
tbonfort committed Sep 16, 2016
1 parent c956fa1 commit 5dacd4168c3b74569fb7c2b1341bbdb2852fe643
Showing with 47 additions and 10 deletions.
  1. +3 −0 include/mapcache.h
  2. +20 −10 lib/service_wmts.c
  3. +24 −0 lib/tileset.c
@@ -1599,6 +1599,9 @@ int mapcache_grid_get_cell(mapcache_context *ctx, mapcache_grid *grid, mapcache_
* @return
*/
void mapcache_tileset_tile_validate(mapcache_context *ctx, mapcache_tile *tile);
void mapcache_tileset_tile_validate_z(mapcache_context *ctx, mapcache_tile *tile);
void mapcache_tileset_tile_validate_x(mapcache_context *ctx, mapcache_tile *tile);
void mapcache_tileset_tile_validate_y(mapcache_context *ctx, mapcache_tile *tile);

/**
* compute level for a given resolution
@@ -802,7 +802,7 @@ void _mapcache_service_wmts_parse_request(mapcache_context *ctx, mapcache_servic

if(!matrixset) {
ctx->set_error(ctx, 404, "received wmts request with no TILEMATRIXSET");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","tilematrixset");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","TileMatrixSet");
return;
} else {
int i;
@@ -814,49 +814,49 @@ void _mapcache_service_wmts_parse_request(mapcache_context *ctx, mapcache_servic
}
if(!grid_link) {
ctx->set_error(ctx, 404, "received wmts request with invalid TILEMATRIXSET %s",matrixset);
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","tilematrixset");
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","TileMatrixSet");
return;
}
}

if(!matrix) {
ctx->set_error(ctx, 404, "received wmts request with no TILEMATRIX");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","tilematrix");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","TileMatrix");
return;
} else {
char *endptr;
level = (int)strtol(matrix,&endptr,10);
if(*endptr != 0 || level < grid_link->minz || level >= grid_link->maxz) {
ctx->set_error(ctx, 404, "received wmts request with invalid TILEMATRIX %s", matrix);
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","tilematrix");
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","TileMatrix");
return;
}
}

if(!tilerow) {
ctx->set_error(ctx, 404, "received wmts request with no TILEROW");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","tilerow");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","TileRow");
return;
} else {
char *endptr;
row = (int)strtol(tilerow,&endptr,10);
if(*endptr != 0 || row < 0) {
ctx->set_error(ctx, 404, "received wmts request with invalid TILEROW %s",tilerow);
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","tilerow");
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","TileRow");
return;
}
}

if(!tilecol) {
ctx->set_error(ctx, 404, "received wmts request with no TILECOL");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","tilecol");
if(kvp) ctx->set_exception(ctx,"MissingParameterValue","TileCol");
return;
} else {
char *endptr;
col = (int)strtol(tilecol,&endptr,10);
if(endptr == tilecol || col < 0) {
ctx->set_error(ctx, 404, "received wmts request with invalid TILECOL %s",tilecol);
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","tilecol");
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","TileCol");
return;
}
}
@@ -960,9 +960,19 @@ void _mapcache_service_wmts_parse_request(mapcache_context *ctx, mapcache_servic
req->tiles[i]->y = y;
if(i==0) {
/* no need to validate all the tiles as they all have the same x,y,z */
mapcache_tileset_tile_validate(ctx,req->tiles[0]);
mapcache_tileset_tile_validate_z(ctx,req->tiles[0]);
if(GC_HAS_ERROR(ctx)) {
if(kvp) ctx->set_exception(ctx,"TileOutOfRange","");
if(kvp) ctx->set_exception(ctx,"InvalidParameterValue","TileMatrix");
return;
}
mapcache_tileset_tile_validate_x(ctx,req->tiles[0]);
if(GC_HAS_ERROR(ctx)) {
if(kvp) ctx->set_exception(ctx,"TileOutOfRange","TileCol");
return;
}
mapcache_tileset_tile_validate_y(ctx,req->tiles[0]);
if(GC_HAS_ERROR(ctx)) {
if(kvp) ctx->set_exception(ctx,"TileOutOfRange","TileRow");
return;
}
}
@@ -151,6 +151,30 @@ void mapcache_tileset_add_watermark(mapcache_context *ctx, mapcache_tileset *til
tileset->watermark = mapcache_imageio_decode(ctx,watermarkdata);
}

void mapcache_tileset_tile_validate_z(mapcache_context *ctx, mapcache_tile *tile) {
if(tile->z < tile->grid_link->minz || tile->z >= tile->grid_link->maxz) {
ctx->set_error(ctx,404,"invalid tile z level");
}
}

void mapcache_tileset_tile_validate_x(mapcache_context *ctx, mapcache_tile *tile) {
mapcache_extent_i limits;
limits = tile->grid_link->grid_limits[tile->z];
if(tile->x<limits.minx || tile->x>=limits.maxx) {
ctx->set_error(ctx, 404, "tile x=%d not in [%d,%d[",
tile->x,limits.minx,limits.maxx);
}
}

void mapcache_tileset_tile_validate_y(mapcache_context *ctx, mapcache_tile *tile) {
mapcache_extent_i limits;
limits = tile->grid_link->grid_limits[tile->z];
if(tile->y<limits.miny || tile->y>=limits.maxy) {
ctx->set_error(ctx, 404, "tile y=%d not in [%d,%d[",
tile->y,limits.miny,limits.maxy);
}
}

void mapcache_tileset_tile_validate(mapcache_context *ctx, mapcache_tile *tile)
{
mapcache_extent_i limits;

0 comments on commit 5dacd41

Please sign in to comment.
You can’t perform that action at this time.