From 6176dd569511e8a9adba60889c95626163178cb5 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 25 Mar 2013 18:23:35 +0000 Subject: [PATCH] fix crash on too big of a request [Close #332] --- modules/link/link.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/link/link.js b/modules/link/link.js index e07c178..94a2287 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -11,7 +11,9 @@ var link = function(dbot) { this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; this.links = {}; this.fetchTitle = function(event, link) { - request(link, function(error, response, body) { + var limit = 25 * 1000, + size = 0, + page = request(link, function(error, response, body) { if(!error && response.statusCode == 200) { body = body.replace(/(\r\n|\n\r|\n)/gm, " "); var title = body.valMatch(/(.*)<\/title>/, 2); @@ -20,6 +22,14 @@ var link = function(dbot) { } } }); + + page.on('data', function(chunk) { + size += chunk.length; + if(size > limit) { + page.abort(); + event.reply('request too big, fuck off'); + } + }); }; var commands = {