Skip Menu |

This queue is for tickets about the GDGraph CPAN distribution.

Maintainer(s)' notes

There are plenty of good ideas of what people can do published here on the queue. Turning a patch from the tracker into a pull request is not one of them. In order to get maintainers' attention way more quickier, PR should have at least a sample included. We know it's hard to test images generating software, but it doesn't mean we can not test numbers produced by intermediate algorithms used to generate these images, so either a test or a sample.

Report information
The Basics
Id: 21610
Status: resolved
Priority: 0/
Queue: GDGraph

People
Owner: Nobody in particular
Requestors: phil [...] ipom.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.4308
Fixed in: 1.44



Subject: Another divide-by-zero bug
Date: Fri, 22 Sep 2006 01:04:27 -0700
To: bug-GDGraph [...] rt.cpan.org
From: Phil Dibowitz <phil [...] ipom.com>
Download signature.asc
application/pgp-signature 252b

Message body not shown because it is not plain text.

I get a divide-by-zero bug when using GD::Graph like so: Illegal division by zero at /usr/lib/perl5/site_perl/5.8.0/GD/Graph/axestype.pm line 1905. This seems to be different than all the other ones currently in RT. I've attached a patch for the issue. Here's the relevant version info: perl: 5.8.0-94.EL3 perl-GD: 1.41 perl-GD-Graph: 1.4308 perl-GD-Text: 0.86 gd: 1.8.4-12.3.1 kernel: 2.4.21-47.ELsmp Red Hat Enterprise Linux AS release 3 (Taroon Update 8) -- Phil Dibowitz phil@ipom.com Freeware and Technical Pages Insanity Palace of Metallica http://www.phildev.net/ http://www.ipom.com/ "Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind." - Dr. Seuss
--- axestype.pm.bk.phil 2006-09-22 00:37:48.000000000 -0700 +++ axestype.pm 2006-09-22 00:58:14.000000000 -0700 @@ -1902,9 +1902,12 @@ my $y_min = $self->{y_min}[$axis]; my $y_max = $self->{y_max}[$axis]; + my $y_diff = $y_max - $y_min; + $y_diff = 1 if ($y_diff == 0); + my $y_step = $self->{rotate_chart} ? - abs(($self->{right} - $self->{left})/($y_max - $y_min)) : - abs(($self->{bottom} - $self->{top})/($y_max - $y_min)); + abs(($self->{right} - $self->{left})/$y_diff) : + abs(($self->{bottom} - $self->{top})/$y_diff); my $ret_x; my $origin = $self->{rotate_chart} ? $self->{top} : $self->{left};
I'm somewhat at a loss what the actual use of a graph with a y-range of zero would be, but I suppose that about guarantees that nobody will complain if I implement your fix. If you're still monitoring this bug, after all these months, and want to explain why I'm wrong about that, please do (a private e-mail would probably do)--I'd be fascinated to learn. On Fri Sep 22 04:04:53 2006, phil@ipom.com wrote: Show quoted text
> I get a divide-by-zero bug when using GD::Graph like so: > > Illegal division by zero at > /usr/lib/perl5/site_perl/5.8.0/GD/Graph/axestype.pm line 1905. > > This seems to be different than all the other ones currently in RT. > > I've attached a patch for the issue. > > Here's the relevant version info: > > perl: 5.8.0-94.EL3 > perl-GD: 1.41 > perl-GD-Graph: 1.4308 > perl-GD-Text: 0.86 > gd: 1.8.4-12.3.1 > kernel: 2.4.21-47.ELsmp > Red Hat Enterprise Linux AS release 3 (Taroon Update 8) >
Subject: Re: [rt.cpan.org #21610] Another divide-by-zero bug
Date: Wed, 11 Apr 2007 23:34:54 -0700
To: bug-GDGraph [...] rt.cpan.org
From: Phil Dibowitz <phil [...] ipom.com>
Benjamin Warfield via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=21610 > > > I'm somewhat at a loss what the actual use of a graph with a y-range of zero would be, but I > suppose that about guarantees that nobody will complain if I implement your fix. If you're > still monitoring this bug, after all these months, and want to explain why I'm wrong about > that, please do (a private e-mail would probably do)--I'd be fascinated to learn.
There are all kinds of data you may be pulling in and graphing on the fly. And if you pull in a bunch of 0s for a while, your max y is... well, 0. :) Since my code isn't using that number to divide by anything, it had no way of knowing it should be bounds checking it as > 0. Regardless of the use, code should never divide anything by a variable without checking it's not 0 first. -- Phil Dibowitz phil@ipom.com Open Source software and tech docs Insanity Palace of Metallica http://www.phildev.net/ http://www.ipom.com/ "Never write it in C if you can do it in 'awk'; Never do it in 'awk' if 'sed' can handle it; Never use 'sed' when 'tr' can do the job; Never invoke 'tr' when 'cat' is sufficient; Avoid using 'cat' whenever possible" -- Taylor's Laws of Programming
Download signature.asc
application/pgp-signature 252b

Message body not shown because it is not plain text.

Oh, I'm perfectly OK with putting in a check to prevent the error, but just plotting a bunch of zeroes doesn't actually hit this error (or at least, not in any of the simple test scenarios I tried out when I was writing a test for it). As far as I can tell, you have to explicitly set the y_min and y_max to the same value to hit this particular bug (which perhaps helps explain why it's gone unnoticed and unfixed for so long). Regardless, I've patched it as you suggested, and I'm hopeful I'll get a new release out in the fairly immediate future.