fix: handle BadZipFile for corrupted media in PPTX converter#1670
Open
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: handle BadZipFile for corrupted media in PPTX converter#1670octo-patch wants to merge 1 commit intomicrosoft:mainfrom
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…icrosoft#1159) When a PPTX file contains a media file with corrupted CRC-32 (e.g., a .m4a audio file), python-pptx raises BadZipFile when reading the media blob. This caused the entire PPTX conversion to fail. Wrap the image blob access inside try/except to catch BadZipFile and other IO errors, logging a warning and continuing with the rest of the presentation. Also fix the adjacent TypeError: if llm_caption returns None, the original join would fail. Use filter(None, ...) to safely skip None and empty values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1159
Problem
When a PPTX file contains a media file with a corrupted CRC-32 checksum (e.g., an embedded
.m4aaudio file), python-pptx raisesBadZipFilewhen reading the media blob during conversion. This caused the entire PPTX conversion to fail with an unhandled exception:Solution
Wrap the
shape.image.blobaccess in atry/exceptblock to catchBadZipFileand other IO errors when reading media files. When a corrupted media file is encountered, log a warning and gracefully continue with the rest of the conversion (using a placeholder image reference instead).Also fix an adjacent
TypeErrorthat would occur ifllm_caption()returnsNone: the original"\n".join([None, alt_text])would fail with aTypeError. Changed to usefilter(None, ...)to safely skipNoneand empty string values before joining.Testing