• Bug with printobject and writeobject (includes a patch)

    From news@zzo38computer.org.invalid@21:1/5 to All on Mon Jun 8 11:50:13 2020
    There is a bug in Ghostscript (which I have reported) having do with the printobject and writeobject operators; sometimes arrays output by those operators are output with the wrong offsets, causing them to be read back incorrectly. If you use these operators, then you may wish to patch this
    bug. (It is also needed if you are using TeXnicard, or any other software
    which uses these operators.)

    Instructions for patching it are provided here, but note that I have not
    signed the Artifex contribution agreement (but I will tell you that I am willing to release my changes into the public domain and that anyone is
    free to apply this patch (subject to the license of Ghostscript), but they might not believe me). This patch is done entirely in PostScript, and does
    not require recompiling Ghostscript.

    The method of working is to use a temporary dictionary to keep track of
    array offeets. The file called Resource/Init/gs_btokn.ps defines the printobject and writeobject operators; change this file as described.

    Find the following code:
    cntdict /arraytype {
    dup dup length 5 -1 roll add 4 2 roll { //.cntobj exec } forall

    After the line with "cntdict /arraytype {", insert the line:
    dup 3 index 3 bitshift def

    This enters the array into a temporary dictionary, together with its
    offset in the binary object format.

    To set up that temporary dictionary, find the definition of .writeobjects
    and add "mark .dicttomark begin" at the beginning, and "end" at the end.

    There is then a forall loop for writing the contents of an array by the
    use of the .bosobject operator; it starts with "(x\000xxxxxx) .bosobject
    dup 1 6 index put". Before the string with the "x"s, add the following:
    dup type /arraytype eq {
    currentdict 1 index known {3 2 roll pop dup load 3 1 roll} if
    } if

    That will find the array offset in the temporary dictionary and will set
    the offset known to .bosobject to that number.

    My tests show that this works, even if there are duplicate objects.

    Also, the authors of Ghostscript may wish to fix it in a different way
    anyways, possibly by an implementation in a C code.

    I also wrote a set of C macros to parse the PostScript binary object
    format, which I will post in a separate article. (These C macros are a
    part of TeXnicard. The above description of the patch is also included
    with TeXnicard, since it is not fixed in the official released version
    of Ghostscript yet.)

    --
    This signature intentionally left blank.
    (But if it has these words, then actually it isn't blank, isn't it?)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)