refac: identify loader archives by content (#33460)

* fix: apply the document archive size guard to every zip file, not just named extensions

The decompression-bomb guard in the document loader only ran when the
filename extension or the declared content type matched a fixed list, so
an office archive renamed to a legacy or unknown extension (for example
an .xlsx saved as .xls, .bin, or served from a URL with no extension)
skipped the check entirely and was fully inflated in the worker. The
guard now detects zip archives by content and checks every one of them,
while non-archive files keep the previous behavior.

* refac: identify loader archives by content

The document loader now recognises archives by their content when checking their size.
This commit is contained in:
Classic298 2026-11-01 01:06:46 +01:00 • committed by GitHub
parent 96c1cfca6e
commit 4adf3083f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,15 +94,6 @@ known_source_ext = [
'svg',
]
known_archive_ext = {'docx', 'epub', 'odt', 'pptx', 'xlsx'}
known_archive_content_types = {
'application/epub+zip',
'application/vnd.oasis.opendocument.text',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
}
class ExcelLoader:
"""Fallback Excel loader using pandas when unstructured is not installed."""
@ -538,7 +529,7 @@ class Loader:
def _get_loader(self, filename: str, file_content_type: str, file_path: str):
file_ext = filename.split('.')[-1].lower()
if file_ext in known_archive_ext or file_content_type in known_archive_content_types:
if zipfile.is_zipfile(file_path):
max_file_size = self.config['rag.file.max_size']
try:
max_file_size_bytes = int(max_file_size) * 1024 * 1024 if max_file_size else 100 * 1024 * 1024