Bug#422712: gs-esp: pstoraster fails with signal 11 when printing cups testpage

2011-01-23 Thread Jonathan Nieder
severity 422712 wishlist
retitle 422712 pstoraster segfaults with ancient cups
tags 422712 - moreinfo
tags 422712 + upstream
quit
(-cc: the world since I have veered off topic)

Troy Rollo wrote:

 I do not recall the precise reasoning behind this, other than that at the 
 time 
 the patch seemed to make sense mathematically and without it there was a 
 segmentation violation
[...]
 The code patched seems to attempt to constrain lasty to a position within 
 the passed in btile, vertically (that is, btile-size.y).

That helps.  If I understand correctly then

by = lasty % btile-size.y;
if (by  0)
by += btile-size.y;

would be another way to convey the same thing.

The context is beyond my depth (and undercommented, I suppose).
wrap_shifted_cursor seems to do something complicated involving
tile_shift, so if I had to guess, the fix would be something like:

ptc-tile.shift = btile-shift;
by = lasty + btile-size.y;
if (by  0)
by += btile-size.y;
bx = endx;
if (ptc-tile.shift) {
int quotient = lasty / btile-size.y;
if (lasty  0)
quotient--;
bx += quotient * ptc-tile.shift;
}
bx %= tw;
if (bx  0)
bx += tw;

What I had been hoping for was something like lasty gets set using
this library call from CUPS, which used to return this out-of-range
but meaningful value but always returns nonnegative values now.
Oh, well.

Maybe it would make sense to do

if (by  0)
... error out with a helpful message ...

I'm marking figuring this out as a wishlist bug for now.

Thanks again.
Jonathan



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#422712: gs-esp: pstoraster fails with signal 11 when printing cups testpage

2011-01-23 Thread Troy Rollo
On Sunday 23 January 2011, Jonathan Nieder wrote:

 That helps.  If I understand correctly then

   by = lasty % btile-size.y;
   if (by  0)
   by += btile-size.y;

 would be another way to convey the same thing.

Probably. The behaviour of the mod operator with negative numbers has been 
undefined at some points in time, and is something that a compiler might get 
wrong - I prefer to avoid applying the modulo function to a negative number 
at all, hence the longer version in my patch.



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#422712: gs-esp: pstoraster fails with signal 11 when printing cups testpage

2011-01-22 Thread Jonathan Nieder
tags 422712 + moreinfo
quit

Hi,

Troy Rollo wrote:

 This only seems to affect applications using the CUPS v1.1 libraries - 
 applications using the CUPS v1.2 libraries seem to work OK.

 diff -ru gs-esp-8.15.3.dfsg.1/src/gxcht.c 
 gs-esp-8.15.3.dfsg.1-fixed/src/gxcht.c
 --- gs-esp-8.15.3.dfsg.1/src/gxcht.c  2005-01-19 15:08:41.0 +1100
 +++ gs-esp-8.15.3.dfsg.1-fixed/src/gxcht.c2007-12-25 19:55:36.0 
 +1100
 @@ -1087,7 +1087,14 @@
  int tw = btile-size.x;
  int bx = ((ptc-tile_shift = btile-shift) == 0 ? endx :
 endx + lasty / btile-size.y * ptc-tile_shift) % tw;
 -int by = lasty % btile-size.y;
 +int by;
 +
 +if (lasty  0)
 + by = btile-size.y - (-lasty % btile-size.y);
 +else
 + by = lasty % btile-size.y;
 +
 +by = lasty % btile-size.y;
  

This patch does not seem to be part of current ghostscript.  Could
you explain what it does?  Is there an example postscript file and gs
invocation that would trigger it, or is it useful for robustness reasons?

Thanks and sorry for the long delay,
Jonathan



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#422712: gs-esp: pstoraster fails with signal 11 when printing cups testpage

2011-01-22 Thread Troy Rollo
On Sunday 23 January 2011, Jonathan Nieder wrote:
 tags 422712 + moreinfo
 quit

 Hi,

 Troy Rollo wrote:
  This only seems to affect applications using the CUPS v1.1 libraries -
  applications using the CUPS v1.2 libraries seem to work OK.
 
  diff -ru gs-esp-8.15.3.dfsg.1/src/gxcht.c
  gs-esp-8.15.3.dfsg.1-fixed/src/gxcht.c ---
  gs-esp-8.15.3.dfsg.1/src/gxcht.c2005-01-19 15:08:41.0 +1100 +++
  gs-esp-8.15.3.dfsg.1-fixed/src/gxcht.c  2007-12-25 19:55:36.0
  +1100 @@ -1087,7 +1087,14 @@
   int tw = btile-size.x;
   int bx = ((ptc-tile_shift = btile-shift) == 0 ? endx :
endx + lasty / btile-size.y * ptc-tile_shift) % tw;
  -int by = lasty % btile-size.y;
  +int by;
  +
  +if (lasty  0)
  +   by = btile-size.y - (-lasty % btile-size.y);
  +else
  +   by = lasty % btile-size.y;
  +
  +by = lasty % btile-size.y;

 This patch does not seem to be part of current ghostscript.  Could
 you explain what it does?  Is there an example postscript file and gs
 invocation that would trigger it, or is it useful for robustness reasons?

That's the wrong version of the patch. The correct version looks like this:

 diff -ru gs-esp-8.15.3.dfsg.1.orig/src/gxcht.c
 gs-esp-8.15.3.dfsg.1/src/gxcht.c --- gs-esp-8.15.3.dfsg.1.orig/src/gxcht.c 
  2007-12-27 09:39:57.0 +1100 +++
 gs-esp-8.15.3.dfsg.1/src/gxcht.c2007-12-27 10:57:54.0 +1100 @@
 -1087,7 +1087,18 @@
  int tw = btile-size.x;
  int bx = ((ptc-tile_shift = btile-shift) == 0 ? endx :
   endx + lasty / btile-size.y * ptc-tile_shift) % tw;
 -int by = lasty % btile-size.y;
 +int by;
 +
 +if (lasty  0)
 +{
 +   by = btile-size.y - (-lasty % btile-size.y);
 +   if (by ==  btile-size.y)
 +   by = 0;
 +}
 +else
 +{
 +   by = lasty % btile-size.y;
 +}

  ptc-xoffset = bx  3;
  ptc-xshift = 8 - (bx  7);

I do not recall the precise reasoning behind this, other than that at the time 
the patch seemed to make sense mathematically and without it there was a 
segmentation violation, however running a short program seems to reveal the 
problem:

 troy@enterprise:~$ cat test.c
 #include stdio.h

 #define TEST(x) printf(#x  = %d\n, x)

 int
 main(int argc, char **argv)
 {
 TEST(5 % 8);
 TEST(-3 % 8);
 return 0;
 }
 troy@enterprise:~$ gcc test.c
 troy@enterprise:~$ ./a.out
 5 % 8 = 5
 -3 % 8 = -3
 troy@enterprise:~$

The code patched seems to attempt to constrain lasty to a position within 
the passed in btile, vertically (that is, btile-size.y). That would mean 
the output had to be in the range (0,btile-size.y - 1). Where lasty is less 
than zero, the modulo formula returns a negative number, so the output is not 
in that range, hence a segmentation violation.

Take f(x) being x % btile-size.y. The following is true for all positive 
integer x and n:

f(x) == f(x + btile-size.y * n)

I assumed that the desired behaviour was to have a function, f(x), that 
behaved like x % btile-size.y for all positive x, but where the above 
relationship was also true if either x or n (or both) was negative. The 
condition does that.

To put it another way, if btile-size.y is 8, then I assumed we want:

f(9) == 1
f(8) == 0
f(7) == 7
f(6) == 6
f(5) == 5
f(4) == 4
f(3) == 3
f(2) == 2
f(1) == 1
f(0) == 0
f(-1) == 7
f(-2) == 6
etc.

Does that sufficiently answer your question?



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#422712: gs-esp: pstoraster fails with signal 11 when printing cups testpage

2007-05-07 Thread James Kelly
Package: gs-esp
Version: 8.15.3.dfsg.1-1
Severity: important

I defined an EPSON Stylus Photo 890 to cups using the gutenprint PPD 
for that printer.  The PPD is automatically generated when 
the cupsys-driver-gutenprint package is installed and can be found at:
/usr/share/ppd/gutenprint/5.0/en/stp-escp2-890.5.0.ppd.gz after 
cupsys-driver-gutenprint is installed.

When I attempt to print anything on this printer it fails.  Turning on 
debug logging in cups I find that:

PID 4440 (/usr/lib/cups/filter/pstoraster) crashed on signal 11!

This occurs for every job sent to this printer.

When I manually run gs-esp using the options in pstoraster with the 
cups testpage as input it works ok.  However if I filter the cups testpage 
first using pstops (which is what cups does), and then put it through 
gs-esp it dies with signal 11.

It would therefore appear that some of the postscript pstops is adding 
from the PPD file is causing gs-esp to choke.  I have another HP 
printer defined on the same box that doesn't cause any problems.

I am reporting this against gs-esp since I would expect it not to 
get a segmentation violation even if there were errors in the 
postscript it processes.  However it is quite possible the cause
of this is something in the PPD file that was autogenerated.

Here are the last 150 lines or so output by pstoraster leading up to the
segmentation violation when cups has debug level logging enabled:

D [08/May/2007:04:09:13 +1000] [Job 7] cups-header.Duplex = 0
D [08/May/2007:04:09:13 +1000] [Job 7] cups-page = 1
D [08/May/2007:04:09:13 +1000] [Job 7] cupsPPD = 0x645e98
D [08/May/2007:04:09:13 +1000] [Job 7] cupsPPD-flip_duplex = 0
D [08/May/2007:04:09:13 +1000] [Job 7] width = 5950, height = 4210
D [08/May/2007:04:09:13 +1000] [Job 7] PageSize = [ 595 842 ], HWResolution = [ 
720 360 ]
D [08/May/2007:04:09:13 +1000] [Job 7] HWMargins = [ 0.000 0.000 0.000 0.000 ]
D [08/May/2007:04:09:13 +1000] [Job 7] matrix = [ 10.000 0.000 0.000 -5.000 
-0.000 4210.000 ]
D [08/May/2007:04:09:13 +1000] [Job 7] Finishing.
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] Checking.
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] Merging.
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] Selecting.
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] Constructing.
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] Putting.
D [08/May/2007:04:09:13 +1000] [595.0 842.0]
D [08/May/2007:04:09:13 +1000] [Job 7] /.MediaSize
D [08/May/2007:04:09:13 +1000] [Job 7] 0
D [08/May/2007:04:09:13 +1000] [Job 7] /%MediaDestination
D [08/May/2007:04:09:13 +1000] [Job 7] 0
D [08/May/2007:04:09:13 +1000] [Job 7] /%MediaSource
D [08/May/2007:04:09:13 +1000] [Job 7] 0
D [08/May/2007:04:09:13 +1000] [Job 7] /MediaPosition
D [08/May/2007:04:09:13 +1000] [Job 7] 8
D [08/May/2007:04:09:13 +1000] [Job 7] /cupsBitsPerColor
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] true
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -device-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] -dict-
D [08/May/2007:04:09:13 +1000] [Job 7] -mark-
D [08/May/2007:04:09:13 +1000] [Job 7] Setting MediaPosition to 0...
D [08/May/2007:04:09:13 +1000] [Job 7] Setting cupsBitsPerColor to 8...
D [08/May/2007:04:09:13 +1000] [Job 7] cupsEncodeLUT[0] = 0
D [08/May/2007:04:09:13 +1000] [Job 7] cupsEncodeLUT[65535] = 255
D [08/May/2007:04:09:13 +1000] [Job 7] num_components =