From b44a7b9aa6263c120aebf88b9aad45a5b114cc84 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 26 Jan 2016 14:52:40 +0000 Subject: [PATCH] reject very large ops --- services/track-changes/app.coffee | 1 + .../track-changes/app/coffee/UpdatesManager.coffee | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/services/track-changes/app.coffee b/services/track-changes/app.coffee index 2faeec2286..e8a00cf8f4 100644 --- a/services/track-changes/app.coffee +++ b/services/track-changes/app.coffee @@ -16,6 +16,7 @@ truncateFn = (updates) -> TrackChangesLogger.addSerializers { rawUpdates: truncateFn newUpdates: truncateFn + rawUpdate: truncateFn lastUpdate: truncateFn } diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index 1047d98240..bffd7f540e 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -47,6 +47,17 @@ module.exports = UpdatesManager = if rawUpdates.length == 0 return callback() + # some old large ops in redis need to be rejected, they predate + # the size limit that now prevents them going through the system + REJECT_LARGE_OP_SIZE = 4 * 1024 * 1024 + for rawUpdate in rawUpdates + opSizes = ((op.i?.length || op.d?.length) for op in rawUpdate?.op or []) + size = _.max opSizes + if size > REJECT_LARGE_OP_SIZE + error = new Error("dropped op exceeding maximum allowed size of #{REJECT_LARGE_OP_SIZE}") + logger.error err: error, doc_id: doc_id, project_id: project_id, size: size, rawUpdate: rawUpdate, "dropped op - too big" + rawUpdate.op = [] + if (not lastCompressedUpdate?) or lastCompressedUpdate.pack? # handle pack append as a special case UpdatesManager._updatePack project_id, doc_id, rawUpdates, temporary, lastCompressedUpdate, lastVersion, callback else #use the existing op code