From e73890bfc22b978712fb6ecc6a385d7a1fd89cc8 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 6 Nov 2015 12:52:03 +0000 Subject: [PATCH] Error if update would make document too long --- .../document-updater/app/coffee/ShareJsUpdateManager.coffee | 2 +- .../document-updater/app/coffee/sharejs/server/model.coffee | 3 +++ services/document-updater/config/settings.defaults.coffee | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/document-updater/app/coffee/ShareJsUpdateManager.coffee b/services/document-updater/app/coffee/ShareJsUpdateManager.coffee index 278a104beb..83786cbb96 100644 --- a/services/document-updater/app/coffee/ShareJsUpdateManager.coffee +++ b/services/document-updater/app/coffee/ShareJsUpdateManager.coffee @@ -15,7 +15,7 @@ ShareJsModel:: = {} util.inherits ShareJsModel, EventEmitter module.exports = ShareJsUpdateManager = - getNewShareJsModel: () -> new ShareJsModel(ShareJsDB) + getNewShareJsModel: () -> new ShareJsModel(ShareJsDB, maxDocLength: Settings.max_doc_length) applyUpdates: (project_id, doc_id, updates, callback = (error, updatedDocLines) ->) -> logger.log project_id: project_id, doc_id: doc_id, updates: updates, "applying sharejs updates" diff --git a/services/document-updater/app/coffee/sharejs/server/model.coffee b/services/document-updater/app/coffee/sharejs/server/model.coffee index 284d6fd770..0e699cce92 100644 --- a/services/document-updater/app/coffee/sharejs/server/model.coffee +++ b/services/document-updater/app/coffee/sharejs/server/model.coffee @@ -136,6 +136,9 @@ module.exports = Model = (db, options) -> catch error console.error error.stack return callback error.message + + if options.maxDocLength? and doc.snapshot.length > options.maxDocLength + return callback "Update takes doc over max doc size" # The op data should be at the current version, and the new document data should be at # the next version. diff --git a/services/document-updater/config/settings.defaults.coffee b/services/document-updater/config/settings.defaults.coffee index fbda700b59..41d25b4ea2 100755 --- a/services/document-updater/config/settings.defaults.coffee +++ b/services/document-updater/config/settings.defaults.coffee @@ -23,6 +23,8 @@ module.exports = zip: minSize: 10*1024 writesEnabled: false + + max_doc_length: 2 * 1024 * 1024 # 2mb mongo: url: 'mongodb://127.0.0.1/sharelatex'