From a4ae0ea12f720ca2477292f4677075b50a5a4fb1 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 6 May 2021 09:39:52 +0100 Subject: [PATCH] [ShareJsUpdateManager] double check doc size before flushing --- .../app/js/ShareJsUpdateManager.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/document-updater/app/js/ShareJsUpdateManager.js b/services/document-updater/app/js/ShareJsUpdateManager.js index 607ae2d9fa..8ae91df32c 100644 --- a/services/document-updater/app/js/ShareJsUpdateManager.js +++ b/services/document-updater/app/js/ShareJsUpdateManager.js @@ -87,6 +87,20 @@ module.exports = ShareJsUpdateManager = { if (error != null) { return callback(error) } + const docSizeAfter = data.snapshot.length + if (docSizeAfter > Settings.max_doc_length) { + const docSizeBefore = lines.join('\n').length + const err = new Error( + 'blocking persistence of ShareJs update: doc size exceeds limits' + ) + logger.error( + { project_id, doc_id, err, docSizeBefore, docSizeAfter }, + err.message + ) + metrics.inc('sharejs.other-error') + const publicError = 'Update takes doc over max doc size' + return callback(publicError) + } // only check hash when present and no other updates have been applied if (update.hash != null && incomingUpdateVersion === version) { const ourHash = ShareJsUpdateManager._computeHash(data.snapshot)