John Heidemann / Other Stuff / Free Unix / idraw rangecheck errors in ghostscript

This web page documents a bug I found in idraw files when viewed on recent versions of ghostscript. Since idraw is an old, old program and some folks probably have lots of these files sitting around (at least I do :-), I wanted to post the problem and solution on a web page so the magic of search engines could share it with others.

Both the problem and the solution have been reported to the idraw authors. I hope that future versions of idraw will be fixed. Unfortunately, this doesn’t fix existing postscript files.

A big thanks to Alex Cherepanov for finding the fix to the problem, and to Redhat’s bugzilla for matching him up with me.

The problem, a solution, a patch.

And now (26-Jul-07) a Perl program (by me), or a shell script (by Christian Müler, thanks!) that fix files.

The Problem

To: ivtools-users@lists.soruceforge.net
Subject: text in idraw giving errors in recent versions of ghostscript
Date: Thu, 08 Aug 2002 18:00:16 -0700
From: John Heidemann


Has anyone else noticed that text in idraw gives errors in recent
versions of ghostscript?

Specificially, if I create a new file with idraw 1.0.6 and put the
text string "foo" in it, the gv the file using ghostscript-6.52-9.4 on
Redhat 7.3, it gives the following error message:

Error: /rangecheckGNU Ghostscript 6.52: Unrecoverable error, exit code 1
 in --get--
Operand stack:
   --nostringval--   --nostringval--   --nostringval--   descender   0   --nostringval--   1
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1038/1476(ro)(G)--   --dict:0/20(G)--   --dict:90/200(L)--   --dict:36/51(L)--   --dict:1/17(L)--   --dict:5/17(L)--   --dict:1/3(L)--   --dict:14/17(ro)(L)--
Current allocation mode is local
Current file position is 10438


Position 10438 is the first character of the "End" just after
the "] Text" line in the file.

This problem didn't happen on Redhat Linux 7.2, but it persists even
if I downgrade ghostview in RH 7.3 to the 7.2 version.  


1. Has anyone else observed this bug?

2. Is this a ghostscript or idraw problem?
(Is idraw wrong and ghostscript is now more conservative in this release, or 
did ghostscript regress.)

I hpoe it's fixable because I have lots of old idraw files that I like
to ghostview!

   -John

A Solution To The Problem

To: ivtools-users@lists.soruceforge.net
Subject: Re: text in idraw giving errors in recent versions of ghostscript
Date: Sun, 13 Oct 2002 22:51:14 -0700
From: John Heidemann


On Aug 8th I reported a problem with idraw that occurs on Rehdat 7.3
systems.  On Aug 22nd Scott Johnson suggested that this was due to a
ghostscript bug.

I reported the problem on Redhat's bug list and Alex Cherepanov
identified the problem as how idraw handles fonts.  I've attached his
message to me about the subject, and am passing this back to
ivtools-users in hopes that (if confirmed) this can make it into
future releases.

   -John Heidemann

----------------------------------------
Date: Mon, 14 Oct 2002 01:05:21 -0400
From: Alex Cherepanov
To: John Heidemann
Subject: Re: Unreadable http://www.isi.edu/~johnh/PUBLIC/idraw_failing_in_ghostscript_020808.idraw

John Heidemann wrote:
> Fixed.  Thanks for catching this.

The sample file is incorrect. It assumes that FontBBox is an
executable array. Although many fonts are designed this way
there is no such requirement in the spec. The file should be
changed as following to work with both executable and literal
arrays.

Regards,
Alex

*** test.ps Mon Oct 14 00:02:53 2002
--- test-hacked.ps  Mon Oct 14 00:53:20 2002
***************
*** 362,368 ****
   gsave
   fgred fggreen fgblue setrgbcolor
   /fontDict printFont printSize scalefont dup setfont def
! /descender fontDict begin 0 [FontBBox] 1 get FontMatrix end
   transform exch pop def
   /vertoffset 1 printSize sub descender sub def {
   0 vertoffset moveto show
--- 362,368 ----
   gsave
   fgred fggreen fgblue setrgbcolor
   /fontDict printFont printSize scalefont dup setfont def
! /descender fontDict begin 0 /FontBBox load 1 get FontMatrix end
   transform exch pop def
   /vertoffset 1 printSize sub descender sub def {
   0 vertoffset moveto show

A Patch

I turned Alex’s fix to the postscript into a patch for idraw-1.0.6:

--- src/Unidraw/psview.c-       2002-10-27 07:15:26.000000000 -0800
+++ src/Unidraw/psview.c        2002-10-27 07:15:45.000000000 -0800
@@ -571,7 +571,7 @@
     out << "gsave\n";
     out << "fgred fggreen fgblue setrgbcolor\n";
     out << "/fontDict printFont printSize scalefont dup setfont def\n";
-    out << "/descender fontDict begin 0 [FontBBox] 1 get FontMatrix end\n";
+    out << "/descender fontDict begin 0 /FontBBox load 1 get FontMatrix end\n";
     out << "transform exch pop def\n";
     out << "/vertoffset 1 printSize sub descender sub def {\n";
     out << "0 vertoffset moveto show\n";

A Perl Fix

#!/usr/bin/perl -w -i~

#
# fix_idraw_bug
# Id: fix_idraw_bug,v 1.2 2005/08/01 17:27:41 johnh Exp johnh 
#
# Copyright (C) 2002 by John Heidemann 
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#

sub usage {
    print STDERR < for details.
END
    exit 1;
}

use strict;

&usage if ($#ARGV >= 0 && $ARGV[0] eq '-?');
&usage if ($#ARGV < 0);

while (<>) {
    s@^/descender fontDict begin 0 \[FontBBox\] 1 get FontMatrix end$@/descender fontDict begin 0 /FontBBox load 1 get FontMatrix end@;
    print;
};

exit 0;

A Shell Fix

#!/bin/sh

if [ "$2" = "" ]
then
       echo usage: $0 input.ps output.ps
       exit 1
fi

sed -e '/^\/descender fontDict begin 0 \[FontBBox\] 1 get FontMatrix end$/ s:\[FontBBox\]:/FontBBox load:' $1 > $2
Copyright © 2002-2016 by John Heidemann