Skip to content

Commit

Permalink
Enforce 500k tile limit at the source, fail in serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jun 19, 2015
1 parent 5d11669 commit f1e142c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/stream-util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var concurrency = Math.ceil(require('os').cpus().length * 16);
var limits = require('mapbox-upload-limits');
var util = require('util');

module.exports = {};
Expand Down Expand Up @@ -54,6 +55,11 @@ function deserialize(data, property) {
}

function serializeTile(tile) {

if (tile.buffer instanceof Buffer && tile.buffer.length > limits.serialtiles.max_tilesize) {
throw new Error('Tile is larger than limit of ' + limits.serializetiles.max_tilesize / 1024 + 'k');
}

var obj = {
z: isNaN(tile.z) ? null : Number(tile.z),
x: isNaN(tile.x) ? null : Number(tile.x),
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
"Konstantin Käfer <kkaefer>"
],
"dependencies": {
"mapbox-upload-limits": "^1.0.1",
"minimist": "~0.2.0",
"progress-stream": "~0.5.x",
"sphericalmercator": "~1.0.1",
"queue-async": "~1.0.7"
"queue-async": "~1.0.7",
"sphericalmercator": "~1.0.1"
},
"devDependencies": {
"coveralls": "~2.11.1",
Expand Down
5 changes: 5 additions & 0 deletions test/stream-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ test('Tile: serialize', function(t) {
expected = '{"z":null,"x":null,"y":null,"buffer":null}';
t.equal(util.serialize(tile), expected, 'serialize garbage tile as expected');

tile = new util.Tile(1, 2, 3, new Buffer(1e9));
t.throws(function() {
util.serialize(tile);
}, 'Tile is larger than limit');

t.end();
});

Expand Down

0 comments on commit f1e142c

Please sign in to comment.