[ShareJsUpdateManager] double check doc size before flushing

This commit is contained in:
Jakob Ackermann 2021-05-06 09:39:52 +01:00
parent 06d1a12782
commit a4ae0ea12f

View file

@ -87,6 +87,20 @@ module.exports = ShareJsUpdateManager = {
if (error != null) { if (error != null) {
return callback(error) 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 // only check hash when present and no other updates have been applied
if (update.hash != null && incomingUpdateVersion === version) { if (update.hash != null && incomingUpdateVersion === version) {
const ourHash = ShareJsUpdateManager._computeHash(data.snapshot) const ourHash = ShareJsUpdateManager._computeHash(data.snapshot)