Reset handler state before reading to avoid any unforseen state accumulation over multiple operations

This commit is contained in:
HERITAGE-XION 2026-01-10 14:49:35 +01:00
parent 3ea5a9ced2
commit 89ccad6db4
5 changed files with 18 additions and 0 deletions

View File

@ -86,6 +86,8 @@ class ExcelHandler(MetadataHandler):
MetadataReadingError: If the workbook is password-protected.
MetadataNotFoundError: If no properties are found.
"""
self.metadata.clear()
self.keys_to_delete.clear()
wb = load_workbook(Path(self.filepath))
try:
if wb.security.workbookPassword is not None:
@ -113,6 +115,7 @@ class ExcelHandler(MetadataHandler):
Raises:
MetadataNotFoundError: If no properties are found.
"""
self.processed_metadata.clear()
wb = load_workbook(Path(self.filepath))
try:
if wb.properties is None:

View File

@ -90,6 +90,10 @@ class ImageHandler(MetadataHandler):
Uses actual format detection to select the appropriate processor.
"""
self.metadata.clear()
self.text_keys_to_delete.clear()
self.tags_to_delete.clear()
self.detected_format = self._detect_format()
processor = self.processors.get(self.detected_format)
@ -111,6 +115,8 @@ class ImageHandler(MetadataHandler):
Uses actual format detection to select the appropriate processor.
"""
self.processed_metadata.clear()
self.clean_pnginfo = None
# Use cached format if available, otherwise detect
if not self.detected_format:
self.detected_format = self._detect_format()

View File

@ -71,6 +71,8 @@ class PDFHandler(MetadataHandler):
MetadataReadingError: If the PDF is encrypted/password-protected.
MetadataNotFoundError: If no metadata is found in the PDF.
"""
self.metadata.clear()
self.keys_to_delete.clear()
with PdfReader(Path(self.filepath)) as reader:
if reader.is_encrypted:
raise MetadataReadingError("File is encrypted.")
@ -93,6 +95,7 @@ class PDFHandler(MetadataHandler):
Raises:
MetadataNotFoundError: If no metadata is found in the PDF.
"""
self.processed_metadata.clear()
with PdfReader(Path(self.filepath)) as reader:
metadata = reader.metadata
if metadata is None:

View File

@ -103,6 +103,8 @@ class PowerpointHandler(MetadataHandler):
Raises:
MetadataNotFoundError: If no properties are found.
"""
self.metadata.clear()
self.keys_to_delete.clear()
prs = Presentation(str(Path(self.filepath)))
try:
if prs.core_properties is None:
@ -128,6 +130,7 @@ class PowerpointHandler(MetadataHandler):
Raises:
MetadataNotFoundError: If no properties are found.
"""
self.processed_metadata.clear()
prs = Presentation(str(Path(self.filepath)))
try:
if prs.core_properties is None:

View File

@ -97,6 +97,8 @@ class WorddocHandler(MetadataHandler):
Raises:
MetadataNotFoundError: If no properties are found.
"""
self.metadata.clear()
self.keys_to_delete.clear()
doc = Document(str(Path(self.filepath)))
try:
if doc.core_properties is None:
@ -122,6 +124,7 @@ class WorddocHandler(MetadataHandler):
Raises:
MetadataNotFoundError: If no properties are found.
"""
self.processed_metadata.clear()
doc = Document(str(Path(self.filepath)))
try:
if doc.core_properties is None: