diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2022-05-17 19:08:44 +0100 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2022-05-17 19:10:00 +0100 |
commit | 0d304a912eabb916e8633000ad240b224ad01d4b (patch) | |
tree | 8afd04d33b121a217c068060cc8bc906218e3dae | |
parent | 55992c655d087ea37066d81d92bc912989fe238f (diff) | |
download | ghostpdl-0d304a912eabb916e8633000ad240b224ad01d4b.tar.gz |
FirstPage/LastPage device - fix order of processing
Bug #705219 "Using ghostscript with the new PDF engine always only outputs 1 page when using -sPageList"
Not sure why this doesn't cause a problem with regular Ghostscript. The
problem is caused by the order of processing page device parameters in
the device.
We started by reading the 'DisablePageHandler' and potentially disabling
the device (which we do for PDF input, as the interpreter handles this).
But we carried on and processed the remaining parameters, some of which
would then reset DisablePageHandler, effectively re-enabling the device.
This commit simply prevents us processing any of the relevant parameters
if the page handler device is disabled.
This isn't something which gets well tested, so there may be additional
bugs lurking.
-rw-r--r-- | base/gdevflp.c | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/base/gdevflp.c b/base/gdevflp.c index 3c1ad1353..d144d0cbb 100644 --- a/base/gdevflp.c +++ b/base/gdevflp.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -411,90 +411,91 @@ flp_put_params(gx_device * dev, gs_param_list * plist) int code, ecode = 0; gs_param_string pagelist; - code = param_read_int(plist, "FirstPage", &dev->FirstPage); + code = param_read_bool(plist, "DisablePageHandler", &temp_bool); if (code < 0) ecode = code; if (code == 0) { - first_last_subclass_data *psubclass_data = dev->subclass_data; + dev->DisablePageHandler = temp_bool; + if (dev->DisablePageHandler == false) { + first_last_subclass_data *psubclass_data = dev->subclass_data; - dev->DisablePageHandler = false; - psubclass_data->PageCount = 0; - if (dev->PageList) { - rc_decrement(dev->PageList, "flp_put_params"); - dev->PageList = NULL; - } - if (psubclass_data->PageArray != NULL) { - gs_free(dev->memory->non_gc_memory, psubclass_data->PageArray, 1, psubclass_data->PageArraySize, "array of pages selected"); - psubclass_data->PageArray = NULL; - psubclass_data->PageArraySize = 0; + psubclass_data->PageCount = 0; } } - code = param_read_int(plist, "LastPage", &dev->LastPage); - if (code < 0) - ecode = code; - if (code == 0) { - first_last_subclass_data *psubclass_data = dev->subclass_data; + if (dev->DisablePageHandler == false) { + code = param_read_int(plist, "FirstPage", &dev->FirstPage); + if (code < 0) + ecode = code; + if (code == 0) { + first_last_subclass_data *psubclass_data = dev->subclass_data; - dev->DisablePageHandler = false; - psubclass_data->PageCount = 0; - if (dev->PageList) { - rc_decrement(dev->PageList, "flp_put_params"); - dev->PageList = NULL; - } - if (psubclass_data->PageArray != NULL) { - gs_free(dev->memory->non_gc_memory, psubclass_data->PageArray, 1, psubclass_data->PageArraySize, "array of pages selected"); - psubclass_data->PageArray = NULL; - psubclass_data->PageArraySize = 0; + dev->DisablePageHandler = false; + psubclass_data->PageCount = 0; + if (dev->PageList) { + rc_decrement(dev->PageList, "flp_put_params"); + dev->PageList = NULL; + } + if (psubclass_data->PageArray != NULL) { + gs_free(dev->memory->non_gc_memory, psubclass_data->PageArray, 1, psubclass_data->PageArraySize, "array of pages selected"); + psubclass_data->PageArray = NULL; + psubclass_data->PageArraySize = 0; + } } - } - code = param_read_bool(plist, "DisablePageHandler", &temp_bool); - if (code < 0) - ecode = code; - if (code == 0) { - dev->DisablePageHandler = temp_bool; - if (dev->DisablePageHandler == false) { + code = param_read_int(plist, "LastPage", &dev->LastPage); + if (code < 0) + ecode = code; + if (code == 0) { first_last_subclass_data *psubclass_data = dev->subclass_data; + dev->DisablePageHandler = false; psubclass_data->PageCount = 0; + if (dev->PageList) { + rc_decrement(dev->PageList, "flp_put_params"); + dev->PageList = NULL; + } + if (psubclass_data->PageArray != NULL) { + gs_free(dev->memory->non_gc_memory, psubclass_data->PageArray, 1, psubclass_data->PageArraySize, "array of pages selected"); + psubclass_data->PageArray = NULL; + psubclass_data->PageArraySize = 0; + } } - } - code = param_read_string(plist, "PageList", &pagelist); - if (code < 0) - ecode = code; + code = param_read_string(plist, "PageList", &pagelist); + if (code < 0) + ecode = code; - if (code == 0 && pagelist.size > 0) { - first_last_subclass_data *psubclass_data = dev->subclass_data; + if (code == 0 && pagelist.size > 0) { + first_last_subclass_data *psubclass_data = dev->subclass_data; - if (dev->PageList) - rc_decrement(dev->PageList, "flp_put_params"); + if (dev->PageList) + rc_decrement(dev->PageList, "flp_put_params"); - if (psubclass_data->PageArray != NULL) { - gs_free(dev->memory->non_gc_memory, psubclass_data->PageArray, 1, psubclass_data->PageArraySize, "array of pages selected"); - psubclass_data->PageArray = NULL; - psubclass_data->PageArraySize = 0; - } + if (psubclass_data->PageArray != NULL) { + gs_free(dev->memory->non_gc_memory, psubclass_data->PageArray, 1, psubclass_data->PageArraySize, "array of pages selected"); + psubclass_data->PageArray = NULL; + psubclass_data->PageArraySize = 0; + } - dev->PageList = (gdev_pagelist *)gs_alloc_bytes(dev->memory->non_gc_memory, sizeof(gdev_pagelist), "structure to hold page list"); - if (!dev->PageList) - return gs_note_error(gs_error_VMerror); - dev->PageList->Pages = (void *)gs_alloc_bytes(dev->memory->non_gc_memory, pagelist.size + 1, "String to hold page list"); - if (!dev->PageList->Pages){ - gs_free(dev->memory->non_gc_memory, dev->PageList, 1, sizeof(gdev_pagelist), "free structure to hold page list"); - dev->PageList = 0; - return gs_note_error(gs_error_VMerror); + dev->PageList = (gdev_pagelist *)gs_alloc_bytes(dev->memory->non_gc_memory, sizeof(gdev_pagelist), "structure to hold page list"); + if (!dev->PageList) + return gs_note_error(gs_error_VMerror); + dev->PageList->Pages = (void *)gs_alloc_bytes(dev->memory->non_gc_memory, pagelist.size + 1, "String to hold page list"); + if (!dev->PageList->Pages){ + gs_free(dev->memory->non_gc_memory, dev->PageList, 1, sizeof(gdev_pagelist), "free structure to hold page list"); + dev->PageList = 0; + return gs_note_error(gs_error_VMerror); + } + memset(dev->PageList->Pages, 0x00, pagelist.size + 1); + memcpy(dev->PageList->Pages, pagelist.data, pagelist.size); + dev->PageList->PagesSize = pagelist.size + 1; + rc_init_free(dev->PageList, dev->memory->non_gc_memory, 1, flp_rc_free_pages_list); + psubclass_data->ProcessedPageList = false; + dev->DisablePageHandler = false; + psubclass_data->PageCount = 0; } - memset(dev->PageList->Pages, 0x00, pagelist.size + 1); - memcpy(dev->PageList->Pages, pagelist.data, pagelist.size); - dev->PageList->PagesSize = pagelist.size + 1; - rc_init_free(dev->PageList, dev->memory->non_gc_memory, 1, flp_rc_free_pages_list); - psubclass_data->ProcessedPageList = false; - dev->DisablePageHandler = false; - psubclass_data->PageCount = 0; } - code = default_subclass_put_params(dev, plist); if (code < 0) |