A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: Ensure checksum comparison is using SHA256 in file handling (#12939)
Trenton Hfa0c4368d774
diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.pyindex a34a3acf9..f85763d5f 100644--- a/src/documents/signals/handlers.py+++ b/src/documents/signals/handlers.py@@ -1,7 +1,6 @@from __future__ import annotationsimport datetime-import hashlibimport loggingimport shutilimport traceback as _tb@@ -54,6 +53,7 @@ from documents.models import WorkflowTriggerfrom documents.permissions import get_objects_for_user_owner_awarefrom documents.plugins.helpers import DocumentsStatusManagerfrom documents.templating.utils import convert_format_str_to_template_format+from documents.utils import compute_checksumfrom documents.workflows.actions import build_workflow_action_contextfrom documents.workflows.actions import execute_email_actionfrom documents.workflows.actions import execute_move_to_trash_action@@ -410,8 +410,7 @@ def _path_matches_checksum(path: Path, checksum: str | None) -> bool:if checksum is None or not path.is_file():return False- with path.open("rb") as f:- return hashlib.md5(f.read()).hexdigest() == checksum+ return compute_checksum(path) == checksumdef _filename_template_uses_custom_fields(doc: Document) -> bool:diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.pyindex dc0fbb74c..2ae04b063 100644--- a/src/documents/tests/test_file_handling.py+++ b/src/documents/tests/test_file_handling.py@@ -221,8 +221,8 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):doc = Document.objects.create(title="document",mime_type="application/pdf",- checksum=hashlib.md5(original_bytes).hexdigest(),- archive_checksum=hashlib.md5(archive_bytes).hexdigest(),+ checksum=hashlib.sha256(original_bytes).hexdigest(),+ archive_checksum=hashlib.sha256(archive_bytes).hexdigest(),filename="old/document.pdf",archive_filename="old/document.pdf",storage_path=old_storage_path,