summaryrefslogtreecommitdiff
path: root/psi
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2022-07-12 15:26:39 +0100
committerChris Liddell <chris.liddell@artifex.com>2022-07-12 15:26:39 +0100
commit2a54c676fe2e5e7b5415302e7a35e34fc3e9db87 (patch)
treef7cd9df203906f8974bcbce51608aea99337d45b /psi
parent782923753061bf95af49e0bb4ca0a55bcaaac825 (diff)
downloadghostpdl-2a54c676fe2e5e7b5415302e7a35e34fc3e9db87.tar.gz
Ensure pdfi stream lives long enough (use stable_memory)
To avoid problems with objects moving in gc memory, we "clone" the PS file object in order to pass it into pdfi (it also avoids problems with the PS code moving the file position under pdfi's feet). In the event of an error from pdfi provoking a Postscript error, we can end up with the underlying file object being closed by a PS restore, while the PDF stream still exists. If that then gets restored away, or gc'ed before the pdfctx_t, it will also try to close the underlying file object, causing problems. Moving the PDF stream to stable memory ensuring it won't get restored away, and won't get gc'ed until after the pdfctx_t is freed (by whatever means). That, in turn, means that the pdfctx_t finalize method can take its special action with the cloned stream, specifically intended to avoid exactly this kind of issue.
Diffstat (limited to 'psi')
-rw-r--r--psi/zpdfops.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/psi/zpdfops.c b/psi/zpdfops.c
index 11dccca99..7023592b0 100644
--- a/psi/zpdfops.c
+++ b/psi/zpdfops.c
@@ -518,8 +518,8 @@ static int zPDFstream(i_ctx_t *i_ctx_p)
s->close_at_eod = false;
pdfctx->ps_stream = s;
- pdfctx->pdf_stream = s_alloc_immovable(imemory, "PDFstream copy of PS stream");
- pdfctx->pdf_stream_memory = imemory;
+ pdfctx->pdf_stream = s_alloc_immovable(imemory->stable_memory, "PDFstream copy of PS stream");
+ pdfctx->pdf_stream_memory = imemory->stable_memory;
if (pdfctx->pdf_stream == NULL)
return_error(gs_error_VMerror);