mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 11:35:57 +00:00
[misc] SafeJsonParse: align the size limit with the frontend->rt limit
frontend -> real-time and doc-updater -> real-time should be in sync. Otherwise we can send a payload to doc-updater, but can not receive the confirmation of it -- and the client will send it again in a loop. Also log the size of the payload.
This commit is contained in:
parent
15244a54be
commit
cb675d38c2
2 changed files with 4 additions and 4 deletions
|
@ -3,8 +3,8 @@ logger = require "logger-sharelatex"
|
|||
|
||||
module.exports =
|
||||
parse: (data, callback = (error, parsed) ->) ->
|
||||
if data.length > (Settings.max_doc_length or 2 * 1024 * 1024)
|
||||
logger.error {head: data.slice(0,1024)}, "data too large to parse"
|
||||
if data.length > Settings.maxUpdateSize
|
||||
logger.error {head: data.slice(0,1024), length: data.length}, "data too large to parse"
|
||||
return callback new Error("data too large to parse")
|
||||
try
|
||||
parsed = JSON.parse(data)
|
||||
|
|
|
@ -8,7 +8,7 @@ describe 'SafeJsonParse', ->
|
|||
beforeEach ->
|
||||
@SafeJsonParse = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": @Settings = {
|
||||
max_doc_length: 16 * 1024
|
||||
maxUpdateSize: 16 * 1024
|
||||
}
|
||||
"logger-sharelatex": @logger = {error: sinon.stub()}
|
||||
|
||||
|
@ -27,7 +27,7 @@ describe 'SafeJsonParse', ->
|
|||
# we have a 2k overhead on top of max size
|
||||
big_blob = Array(16*1024).join("A")
|
||||
data = "{\"foo\": \"#{big_blob}\"}"
|
||||
@Settings.max_doc_length = 2 * 1024
|
||||
@Settings.maxUpdateSize = 2 * 1024
|
||||
@SafeJsonParse.parse data, (error, parsed) =>
|
||||
@logger.error.called.should.equal true
|
||||
expect(error).to.exist
|
||||
|
|
Loading…
Reference in a new issue