A plain-UTF-8 text file with a .pptx extension. The library must raise a typed opc-level exception; a bare zipfile.BadZipFile leaks implementation detail.
Library verdicts: python-pptx: — pptxjs: —
| Feature id | pptx/malformed-non-zip |
|---|---|
| Format | pptx |
| Category | malformed-recovery |
| Spec | ecma-376-5-part-2 § 10.1.1 Package |
No XPath assertions declared.
No render assertions declared.
scripts/gen_malformed_non_zip_pptx.py
#!/usr/bin/env python3
"""Generate ``fixtures/pptx/malformed-non-zip.pptx``.
A plain-UTF-8 text file with a ``.pptx`` extension. python-pptx must
raise a typed ``PackageNotFoundError`` (the upstream idiom), not a
bare ``zipfile.BadZipFile``.
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _malformed_common import write_plain_bytes
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "pptx" / "malformed-non-zip.pptx"
_PAYLOAD = (
b"This file has a .pptx extension but is plain UTF-8 text, not a "
b"ZIP archive. A conforming reader must reject it with a typed "
b"opc-level exception, not a bare zipfile.BadZipFile.\n"
) * 4
def main() -> int:
_OUT.parent.mkdir(parents=True, exist_ok=True)
write_plain_bytes(_OUT, _PAYLOAD)
print(_OUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
{
"id": "pptx/malformed-non-zip",
"title": "Malformed input: file is not a ZIP archive",
"format": "pptx",
"category": "malformed-recovery",
"summary": "A plain-UTF-8 text file with a .pptx extension. The library must raise a typed opc-level exception; a bare zipfile.BadZipFile leaks implementation detail.",
"roles": [
"authoring"
],
"spec": {
"source": "ecma-376-5-part-2",
"clause": "10.1.1",
"element": "Package",
"notes": "An OPC package is a ZIP. Not-a-zip input is the most basic 'reject gracefully' case."
},
"fixtures": {
"machine": "pptx/malformed-non-zip"
},
"generator": {
"python": "scripts/gen_malformed_non_zip_pptx.py"
},
"behavior_assertions": [
{
"id": "raises-typed-exception",
"kind": "library_raises",
"library": "python-pptx",
"method": "pptx.Presentation",
"args": [
"{fixture_path}"
],
"expected_exception": [
"PackageNotFoundError",
"OpcError"
],
"forbidden_exception": "BadZipFile",
"description": "Must raise a typed opc exception — NOT a bare zipfile.BadZipFile."
}
]
}
No rendered reference is available for this case.