Repository navigation
Conversation
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.
Summary
pdfplumber/repair.pyinvokes Ghostscript on PDFs that are, by the natureof the repair path, damaged or untrusted — but without
-dSAFER, and withno timeout:
Without
-dSAFER, a crafted PDF can direct Ghostscript to read or writearbitrary files through PostScript operators while it is supposedly just
being rewritten. Without a timeout, a hostile or pathological PDF can make
the repair run forever.
Changes (
pdfplumber/repair.pyonly)-dSAFER,-dNOPAUSE, and-dBATCHto the Ghostscript arguments,immediately after the executable.
-dSAFERis the substantive change;-o -already implies batch behaviour on modern Ghostscript, so-dNOPAUSE/-dBATCHare belt-and-braces for older builds._repair()gainstimeout: Optional[float] = 60.0(Nonedisables).On
subprocess.TimeoutExpiredthe child is killed and reaped(
proc.kill()thenproc.communicate()) before the exceptionpropagates —
communicate()alone leaves Ghostscript running.repair()accepts the sametimeoutparameter and forwardsit to
_repair(), so callers can actually set it.Tests
tests/test_repair_safeguards.pyuses stub Ghostscript executables (shellscripts) instead of a real
gs:-dSAFER,-dNOPAUSE, and-dBATCHarepassed, and that repair output flows through unchanged;
exec sleep 60, PID recorded) proves the timeout firespromptly through the public
repair()API and through_repair(),and that the Ghostscript process is actually dead afterwards;
Every safeguard test fails on 0.11.10 and passes with this patch; the
control test (repair via the stub without the new kwarg) passes on both.
On this branch, the existing
tests/test_repair.pysuite (7 tests, realGhostscript) also passes unchanged.
Relation to #1404
#1404 (open) adds
-dSAFERalone, with the same motivation. This PR wasprepared independently; it includes that flag so the change is complete
on its own, and adds the part #1404 does not cover: the timeout, its
forwarding through the public
repair()API, and the kill/reap onexpiry. If #1404 lands first, the
-dSAFERline is the only overlapand the rest rebases trivially.
Disclosure: this contribution was prepared by Árbol, an AI assistant working under the direction of the account holder (scks1), who set the acceptance criteria and verified the results before submission.