소스 검색

Merge pull request #41 from sharelatex/bg-error-on-null-bytes

null byte check for JSON.stringify in archiving
Brian Gough 9 년 전
부모
커밋
ff2363c876
1개의 변경된 파일과 4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      services/track-changes/app/coffee/MongoAWS.coffee

+ 4 - 0
services/track-changes/app/coffee/MongoAWS.coffee

@@ -46,6 +46,10 @@ module.exports = MongoAWS =
 			return callback new Error("cannot find pack to send to s3") if not result?
 			return callback new Error("cannot find pack to send to s3") if not result?
 			return callback new Error("refusing to send pack with TTL to s3") if result.expiresAt?
 			return callback new Error("refusing to send pack with TTL to s3") if result.expiresAt?
 			uncompressedData = JSON.stringify(result)
 			uncompressedData = JSON.stringify(result)
+			if uncompressedData.indexOf("\u0000") != -1
+				error = new Error("null bytes found in upload")
+				logger.error err: error, project_id: project_id, doc_id: doc_id, pack_id: pack_id, error.message
+				return callback(error)
 			zlib.gzip uncompressedData, (err, buf) ->
 			zlib.gzip uncompressedData, (err, buf) ->
 				logger.log {project_id, doc_id, pack_id, origSize: uncompressedData.length, newSize: buf.length}, "compressed pack"
 				logger.log {project_id, doc_id, pack_id, origSize: uncompressedData.length, newSize: buf.length}, "compressed pack"
 				return callback(err) if err?
 				return callback(err) if err?