-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Proper WMF/EMF image handling in PPTXReader #17819
base: main
Are you sure you want to change the base?
Fix: Proper WMF/EMF image handling in PPTXReader #17819
Conversation
output_path = file_path.with_suffix(".png") | ||
|
||
if sys.platform == "win32": | ||
libreoffice_path = r"C:\Program Files\LibreOffice\program\soffice.exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhhh this is a pretty strong assumption on the location of this executable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, how about just searching for the path first, and if nothing was found checking for default installation paths as fallback. I also created a new function with the single purpose of finding the libreoffice path, and put the basic imports into the import section.
def find_libreoffice(self) -> str:
"""Finds the LibreOffice executable path."""
libreoffice_path = shutil.which("soffice")
if not libreoffice_path and sys.platform == "win32":
# Check common installation paths on Windows
possible_paths = [
r"C:\Program Files\LibreOffice\program\soffice.exe",
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
]
libreoffice_path = next(
(path for path in possible_paths if os.path.exists(path)), None
)
if not libreoffice_path:
raise OSError(
"LibreOffice (soffice) not found. Please install LibreOffice or add it to your system PATH."
)
return libreoffice_path
def convert_wmf_to_png(self, input_path: str) -> str:
"""Convert WMF/EMF to PNG using LibreOffice."""
file_path = Path(input_path)
output_path = file_path.with_suffix(".png")
libreoffice_path = self.find_libreoffice()
subprocess.run(
[
libreoffice_path,
"--headless",
"--convert-to",
"png",
"--outdir",
str(file_path.parent),
str(file_path),
],
check=True,
)
return str(output_path)
749075e
to
3a53caf
Compare
3a53caf
to
e316a1c
Compare
Description
This PR fixes a bug in
PPTXReader
where.wmf
and.emf
images cause crashes due toPIL.Image.open()
not supporting these formats.Key Changes:
.wmf
and.emf
images are automatically converted to PNG before processing.PIL.Image.open()
to prevent crashes from unreadable or corrupt images.Fixes: #17820
New Package?
Version Bump?
Type of Change
How Has This Been Tested?
.wmf
and.emf
images.Suggested Checklist
make format; make lint
to ensure proper formatting.