Skip to content

fix: raise clear errors on corrupt or malicious DOCX parsing - #1583

Closed
ChenfromChina123 wants to merge 1 commit into
python-openxml:masterfrom
ChenfromChina123:fix/corrupt-docx-exceptions
Closed

fix: raise clear errors on corrupt or malicious DOCX parsing#1583
ChenfromChina123 wants to merge 1 commit into
python-openxml:masterfrom
ChenfromChina123:fix/corrupt-docx-exceptions

Conversation

@ChenfromChina123

Copy link
Copy Markdown

What does this PR do?

Prevents low-level zlib.error, EOFError, and RuntimeError exceptions from leaking out of docx.Document(stream) when a malformed, corrupt, or maliciously modified DOCX (ZIP) is parsed.

Closes #1561

Changes

  • src/docx/opc/phys_pkg.py: _ZipPkgReader.__init__ raises PackageNotFoundError on BadZipFile/zlib errors; blob_for raises ValueError on member read failures.

Verification

  • Corrupt zip blob → PackageNotFoundError (tested).
  • Normal zip read still returns correct blob (tested).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled exceptions (zlib.error, EOFError, RuntimeError) during malicious/corrupt DOCX parsing

1 participant