Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
rocketchat: Handle long or invalid rocketchat attachment names.
Florian Pritz96fa0991f8ef
diff --git a/zerver/data_import/rocketchat.py b/zerver/data_import/rocketchat.pyindex ab15074e600..6bf3554b243 100644--- a/zerver/data_import/rocketchat.py+++ b/zerver/data_import/rocketchat.py@@ -3,6 +3,7 @@ import osimport randomimport secretsimport subprocess+import uuidfrom typing import Any, Dict, List, Set, Tupleimport bson@@ -373,12 +374,22 @@ def process_message_attachment(if file_ext.lower() in IMAGE_EXTENSIONS:has_image = True+ try:+ sanitized_name = sanitize_name(file_name)+ except AssertionError: # nocoverage+ logging.info("Replacing invalid attachment name with random uuid: %s", file_name)+ sanitized_name = uuid.uuid4().hex++ if len(sanitized_name) >= 255: # nocoverage+ logging.info("Replacing too long attachment name with random uuid: %s", file_name)+ sanitized_name = uuid.uuid4().hex+s3_path = "/".join([str(realm_id),format(random.randint(0, 255), "x"),secrets.token_urlsafe(18),- sanitize_name(file_name),+ sanitized_name,])