projects/guix·blob python-team · refs

57 lines · 4.1 KiB

1This patch makes the "/ID" field optional.
2
3If the environment variable GS_GENERATE_UUIDS is set to "0" or "no", it will
4not write out the "/ID" field (if that's permissible).
5
6Upstream does not want to do this.
7
8See: https://bugs.ghostscript.com/show_bug.cgi?id=698208
9diff --git a/devices/vector/gdevpdf.c b/devices/vector/gdevpdf.c
10index c5abefde2..3859fc088 100644
11--- a/devices/vector/gdevpdf.c
12+++ b/devices/vector/gdevpdf.c
13@@ -1909,8 +1909,11 @@ static int pdf_linearise(gx_device_pdf *pdev, pdf_linearisation_t *linear_params
14 * +1 for the linearisation dict and +1 for the primary hint stream.
15 */
16 linear_params->FirsttrailerOffset = gp_ftell(linear_params->Lin_File.file);
17- gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R/ID[%s%s]/Prev %d>>\nstartxref\r\n0\n%%%%EOF\n \n",
18- linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber, fileID, fileID, 0);
19+ gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R",
20+ linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber);
21+ if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 && strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) /* ID is mandatory when encrypting */
22+ gs_snprintf(LDict, sizeof(LDict), "/ID[%s%s]", fileID, fileID);
23+ gs_snprintf(LDict, sizeof(LDict), "/Prev %d>>\nstartxref\r\n0\n%%%%EOF\n \n", 0);
24 gp_fwrite(LDict, strlen(LDict), 1, linear_params->Lin_File.file);
25
26 /* Write document catalog (Part 4) */
27@@ -2445,8 +2448,11 @@ static int pdf_linearise(gx_device_pdf *pdev, pdf_linearisation_t *linear_params
28 if (code != 0)
29 return_error(gs_error_ioerror);
30
31- gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R/ID[%s%s]/Prev %"PRId64">>\nstartxref\r\n0\n%%%%EOF\n",
32- linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber, fileID, fileID, mainxref);
33+ gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R",
34+ linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber);
35+ if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) /* ID is mandatory when encrypting */
36+ gs_snprintf(LDict, sizeof(LDict), "/ID[%s%s]", fileID, fileID);
37+ gs_snprintf(LDict, sizeof(LDict), "/Prev %"PRId64">>\nstartxref\r\n0\n%%%%EOF\n", mainxref);
38 gp_fwrite(LDict, strlen(LDict), 1, linear_params->sfile);
39
40 code = gp_fseek(linear_params->sfile, pdev->ResourceUsage[HintStreamObj].LinearisedOffset, SEEK_SET);
41@@ -3139,10 +3145,12 @@ pdf_close(gx_device * dev)
42 stream_puts(s, "trailer\n");
43 pprintld3(s, "<< /Size %ld /Root %ld 0 R /Info %ld 0 R\n",
44 pdev->next_id, Catalog_id, Info_id);
45- stream_puts(s, "/ID [");
46- psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
47- psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
48- stream_puts(s, "]\n");
49+ if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) { /* ID is mandatory when encrypting */
50+ stream_puts(s, "/ID [");
51+ psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
52+ psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
53+ stream_puts(s, "]\n");
54+ }
55 if (pdev->OwnerPassword.size > 0) {
56 pprintld1(s, "/Encrypt %ld 0 R ", Encrypt_id);
57 }