You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Working with your library extensively today (it's great!), I noticed that whenever the pdftk subprocess crashes, some artifacts are not being cleaned up from /tmp.
Here is a proof that asserts that in case of a pdftk crash, the generated FDF remains in /tmp:
importosimportreimportsubprocessfrompypdftkimportfill_formdatas= {
# this is gonna crash pdftk, because the angle bracket is not escaped'Given Name Text Box': '1 < 2'
}
try:
fill_form('./OoPdfFormExample.pdf', datas=datas, out_file='out.pdf')
exceptsubprocess.CalledProcessErrorase:
fdf_file=re.match(r'^.+(/tmp/.+?)\s', str(e)).group(1)
assertos.path.exists(fdf_file)
An opening angle bracket makes pdftk crash, because it's rendered into the XML as-is and not escaped (that's an issue of it's own - gonna file that too).
If run_command(cmd, True) raises, first the except, then the finally block are executed. Because the except block re-raises, the last two lines (after the finally) block are never executed. So in case cleanOnFail is False (when outfile is being passed as an argument), the tmp_fdf is never removed.
There is another bug hiding in this: If outfile is not being passed, a temporary file is created and a handle is opened:
In the finally block, the handle is closed, but the out_file is not being removed (although the failing pdftk already created the file, even though it's 0 bytes. It almost looks like a copy-paste problem, that if cleanOnFail is True, actually os.remove(out_file) should have been called?
I can fix both problems and create a PR, if you like.
The text was updated successfully, but these errors were encountered:
Working with your library extensively today (it's great!), I noticed that whenever the pdftk subprocess crashes, some artifacts are not being cleaned up from
/tmp
.Here is a proof that asserts that in case of a pdftk crash, the generated FDF remains in
/tmp
:(The PDF sample is taken from this source)
An opening angle bracket makes pdftk crash, because it's rendered into the XML as-is and not escaped (that's an issue of it's own - gonna file that too).
The
fill_form
function looks like this:If
run_command(cmd, True)
raises, first theexcept
, then thefinally
block are executed. Because theexcept
block re-raises, the last two lines (after thefinally
) block are never executed. So in casecleanOnFail
isFalse
(whenoutfile
is being passed as an argument), thetmp_fdf
is never removed.There is another bug hiding in this: If
outfile
is not being passed, a temporary file is created and a handle is opened:In the
finally
block, the handle is closed, but theout_file
is not being removed (although the failing pdftk already created the file, even though it's 0 bytes. It almost looks like a copy-paste problem, that ifcleanOnFail
isTrue
, actuallyos.remove(out_file)
should have been called?I can fix both problems and create a PR, if you like.
The text was updated successfully, but these errors were encountered: