Skip to content

Commit

Permalink
fix MongoDB BSONObjectTooLarge conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
nbargnesi committed Nov 13, 2024
1 parent c6b8355 commit 5329b7a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/reporting/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,19 @@ def run(self, results):
try:
mongo_insert_one("analysis", report)
except OperationFailure as e:
# ToDo rewrite how children are stored
if str(e).startswith("BSONObj exceeds maximum nested object"):
log.debug("Deleting behavior process tree children from results.")
# check for error code 10334, BSONObjectTooLarge
if e.code == 10334:
# ToDo rewrite how children are stored
log.warning("Deleting behavior process tree children from results.")
del report["behavior"]["processtree"][0]["children"]
try:
mongo_insert_one("analysis", report)
except Exception as e:
log.error("Deleting behavior process tree parent from results: %s", str(e))
del report["behavior"]["processtree"][0]
mongo_insert_one("analysis", report)
else:
raise CuckooReportError("Failed inserting report in Mongo") from e
except InvalidDocument as e:
if str(e).startswith("cannot encode object") or "must not contain" in str(e):
self.loop_saver(report)
Expand Down

0 comments on commit 5329b7a

Please sign in to comment.