A pptx archive whose [Content_Types].xml part has been removed. The library must raise a typed opc-level exception; a bare KeyError leaking from the zip layer is a library bug.
Library verdicts: python-pptx: — pptxjs: —
| Feature id | pptx/malformed-content-types-missing |
|---|---|
| Format | pptx |
| Category | malformed-recovery |
| Spec | ecma-376-5-part-2 § 10.1.2.2 Types |
No XPath assertions declared.
No render assertions declared.
scripts/gen_malformed_content_types_missing_pptx.py
#!/usr/bin/env python3
"""Generate ``fixtures/pptx/malformed-content-types-missing.pptx``.
Known-good one-slide presentation with ``[Content_Types].xml``
removed. python-pptx must raise a typed opc-level exception; a bare
``KeyError`` from the underlying zip reader is a library bug.
"""
from __future__ import annotations
import datetime as _dt
import sys
import tempfile
from pathlib import Path
from pptx import Presentation
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _malformed_common import rewrite_zip
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "pptx" / "malformed-content-types-missing.pptx"
def _drop(name: str, data: bytes) -> bytes | None:
if name == "[Content_Types].xml":
return None
return data
def main() -> int:
_OUT.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(suffix=".pptx", delete=False) as tmp:
good = Path(tmp.name)
try:
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = "content-types-missing slide"
prs.save(good, zip_date_time=_dt.datetime(1980, 1, 1, 0, 0, 0))
rewrite_zip(good, _OUT, edit=_drop)
finally:
good.unlink(missing_ok=True)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"id": "pptx/malformed-content-types-missing",
"title": "Malformed input: [Content_Types].xml missing",
"format": "pptx",
"category": "malformed-recovery",
"summary": "A pptx archive whose [Content_Types].xml part has been removed. The library must raise a typed opc-level exception; a bare KeyError leaking from the zip layer is a library bug.",
"roles": [
"authoring"
],
"spec": {
"source": "ecma-376-5-part-2",
"clause": "10.1.2.2",
"element": "Types",
"notes": "Same mandate as docx/malformed-content-types-missing — part 2 clause 10.1.2.2."
},
"fixtures": {
"machine": "pptx/malformed-content-types-missing"
},
"generator": {
"python": "scripts/gen_malformed_content_types_missing_pptx.py"
},
"behavior_assertions": [
{
"id": "raises-typed-exception",
"kind": "library_raises",
"library": "python-pptx",
"method": "pptx.Presentation",
"args": [
"{fixture_path}"
],
"expected_exception": [
"PackageNotFoundError",
"OpcError",
"KeyError"
],
"forbidden_exception": "KeyError",
"description": "Must raise a typed opc-level exception. A bare KeyError is explicitly forbidden (that's what python-pptx leaks today — a latent bug)."
}
]
}
No rendered reference is available for this case.