Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tilestrata hangs up on vector layer when fed with incorrect coordinates #4

Open
forsetius opened this issue Sep 7, 2016 · 2 comments

Comments

@forsetius
Copy link

forsetius commented Sep 7, 2016

Hello,
The tilestrata serve hangs when incorrect (out of range) coordinates are requested. Say, the request is: http://192.168.0.1:8080/vtile/8/17927/10954/t.pbf. The values for x and y are way too high and as a result server outputs:

/home/osmdebian/node/osm-server/node_modules/tilestrata-vtile/backend.js:119
                map.render(new mapnik.VectorTile(z, x, y), options, function(err, image) {
                           ^

TypeError: required parameter x is out of range of possible values based on z value
    at TypeError (native)
    at /home/osmdebian/node/osm-server/node_modules/tilestrata-vtile/backend.js:119:14
    at /home/osmdebian/node/osm-server/node_modules/tilestrata-vtile/node_modules/mapnik-pool/node_modules/generic-pool/lib/generic-pool.js:291:11
    at loaded (/home/osmdebian/node/osm-server/node_modules/tilestrata-vtile/node_modules/mapnik-pool/index.js:27:28)

Sometimes it exits with error and sometimes hangs so severely it can't be killed with SIGTERM, only SIGKILL does the job.
Interestingly, the problem doesn't show up when requesting raster tiles. In that case I end up with message "http://192.168.0.1:8080/rtile/8/17927/10954/t.png image cannot be shown because it contains errors" (I believe it is correct translation).

In my app I resolved this problem with a request hook:

// lib/inputValidator.js
var rValidator = require('validator');

module.exports = function(options) {
    return {
        name: 'coordChecker',
        reqhook: function(server, tile, req, res, callback) {
            var max = Math.pow(2,tile.z);
            if (rValidator.isAlphanumeric(tile.layer + '') &&
                rValidator.isInt(tile.x + '', {'min': 0, 'max': max, 'allow_leading_zeroes': false}) &&
                rValidator.isInt(tile.y + '', {'min': 0, 'max': max, 'allow_leading_zeroes': false}) &&
                rValidator.isInt(tile.z + '', {'min': 0, 'max': 24, 'allow_leading_zeroes': false})
                ) {
            console.log('Served '+tile.layer+'/'+tile.z+'/'+tile.x+'/'+tile.y);
            callback();
            } else {
                console.log();
                console.log(rValidator.isAlphanumeric(tile.layer + ''));
                console.log(rValidator.isInt(tile.x + '', {'min': 0, 'max': max, 'allow_leading_zeroes': false}));
                console.log(rValidator.isInt(tile.y + '', {'min': 0, 'max': max, 'allow_leading_zeroes': false}));
                console.log(rValidator.isInt(tile.z + '', {'min': 0, 'max': 24, 'allow_leading_zeroes': false}));
            }
        }
    };
};

For validation I use Validator.

This does the job but I really think that end-user shouldn't have the possibility to crash the server in such a way and such protection should be included in the Tilestrata itself. I don't know if it should go to tilestrata or tilestrata-vtile though.

@brianreavis
Copy link
Member

Thanks for the detailed report @forsetius! I think this should be implemented at the tilestrata level. I'll try to get this patched up in the next few days and will let you know. I can't really speak to mapnik throwing / hanging... it shouldn't behave like that. Ideally it'd just return an error to the callback.

@geor-g
Copy link

geor-g commented Jan 6, 2017

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants