T09 · Insecure Skill Coding Practices
- Location
scripts/extract_ofd.py:44- Finding
Unbounded OFD Archive Processing Enables Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/extract_ofd.py, lines 44–45, 85, 105, and 129
Vulnerability Type: Unrestricted ZIP archive decompression and in-memory XML processing
Risk Level: MediumVulnerable Code
python with zipfile.ZipFile(ofd_path, 'r') as zf: # First: parse Document.xml to obtain the template-page mapping template_map = extract_template_map(zf) # Second: locate every page content file content_files = sorted([ name for name in zf.namelist() if 'Pages/Page_' in name and name.endswith('/Content.xml') ])python doc_content = zf.read(doc_path).decode('utf-8')python content_xml = zf.read(page_path).decode('utf-8')python tpl_content = zf.read(tpl_path).decode('utf-8')Technical Analysis
OFD files are ZIP archives whose contents are controlled by the file provider. The extractor enumerates all entries and loads matching document, page, and template XML entries entirely into memory through
ZipFile.read().No validation limits are imposed on:
- The number of archive entries
- The uncompressed size of an individual entry
- The cumulative uncompressed size
- The compression ratio
- The number of pages or templates processed
- XML and text complexity
- Execution time or memory consumption
Consequently, a malicious archive can declare very large uncompressed XML entries despite having a small compressed size. The implementation may hold the decoded XML string, regular-expression results, and extracted output objects in memory simultaneously. Archives containing many qualifying page or template entries can also force repeated decompression, regex scanning, text extraction, sorting, and character-position calculation.
Although the implementation does not extract entries to the filesystem and therefore does not expose a demonstrated ZIP path-traversal issue, its unrestricted in-memory e ...[truncated 1615 chars]
- Remediation
View remediation
Remediation Suggestions
-
Inspect every
ZipInforecord before reading archive content and reject archives that exceed strict limits for:- Maximum entry count
- Maximum uncompressed size per entry
- Maximum cumulative uncompressed size
- Maximum compressed-to-uncompressed ratio
- Maximum page and template count
-
Apply checks immediately before every read rather than relying only on an initial archive-wide check. Track cumulative bytes across document, page, and template reads.
-
Permit only expected OFD XML locations and reject duplicate, encrypted, malformed, or suspiciously named entries.
-
Avoid unrestricted
zf.read(). Open entries withzf.open()and read them incrementally through a bounded reader that aborts when the configured byte limit is reached. -
Parse XML incrementally where feasible and impose limits on extracted text length,
TextObjectcount,TextCodecount, and generated character-position records. -
Run untrusted document processing with OS-enforced memory, CPU, and execution-time limits. In service deployments, isolate extraction in a disposable least-privileged worker.
-
Catch
zipfile.BadZipFile, decompression errors, decoding failures, and resource-limit exceptions separately, returning a controlled validation error without retrying the same file indefinitely. -
Add regression tests using archives with excessive entry counts, large declared sizes, extreme compression ratios, oversized XML text, and many matching page/template entries.
-
