Skip Menu |

This queue is for tickets about the Imager CPAN distribution.

Report information
The Basics
Id: 20403
Status: resolved
Priority: 0/
Queue: Imager

People
Owner: TONYC [...] cpan.org
Requestors: erik [...] urbanninja.se
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.44
Fixed in: 0.52



Subject: Imager crashes when rendering non-antialiased text containing spaces
When trying to render text with string(), perl crashes with the message "Floating point exception". The following code is enough to reproduce the bug on my system: ===== BEGIN CODE ===================== #!/usr/bin/perl use strict; use Imager; use Imager::Font; my $String = $ARGV[0]; my $FontFile = "/var/local/xcms/xcms5dev/fonts/silkscreen.ttf"; my $Font = Imager::Font->new(file => $FontFile, aa => 0, color => "#FF0000", size => 8) or die("Bad font $FontFile\n"); my $Img = Imager->new(xsize => 400, ysize => 300); $Img->string(x => 50, y => 50, font => $Font, text => $String) or die $Img->errstr(); print "OK\n"; ===== END CODE ======================= Running this code: erik@emilia:~/perltest/Imager$ ./bug.pl "test" OK erik@emilia:~/perltest/Imager$ ./bug.pl "test test" Floating point exception I'm using the debian/linux distribution of Imager Perl is v5.8.4 built for i386-linux-thread-multi uname -a gives "Linux emilia 2.6.8-11-em64t-p4-smp #1 SMP Sun Oct 2 20:58:45 UTC 2005 x86_64 GNU/Linux"
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #20403] Imager crashes when rendering non-antialiased text containing spaces
Date: Tue, 11 Jul 2006 10:16:18 +1000
To: Guest via RT <bug-Imager [...] rt.cpan.org>
From: Tony Cook <tony [...] develop-help.com>
On Mon, Jul 10, 2006 at 06:51:28PM -0400, Guest via RT wrote: Show quoted text
> When trying to render text with string(), perl crashes with the message "Floating point > exception". The following code is enough to reproduce the bug on my system:
Thanks for reporting this problem. I've tried to reproduce this, both with Imager 0.49 and Imager 0.44, in both cases it ran to completion. I used a slkscr.ttf downloaded from http://www.kottke.org/plus/type/silkscreen/, since I couldn't find a silkscreen font in Debian. There was a problem in 0.45 that could crash Imager if you output a single space, this was fixed in 0.46. If you have the time, could you please produce a backtrace of the crash? To do this: # build Imager with debugging information perl Makefile.PL OPTIMIZE=-g make # run your code under gdb gdb perl # now in gdb, the -Mblib means to use the add the uninstalled module # built in the current directory to @INC r -Mblib yourscript.pl When the exception occurs, gdb should take control again: # produce the backtrace bt Thanks Tony
From: erik [...] urbanninja.se
I installed Imager 0.51 via CPAN and tested with different fonts, but the problem remains. Show quoted text
> If you have the time, could you please produce a backtrace of the crash?
I'm not very good at this, unfortunately. I can't even get gdb to work (see results below). Seems that this it is not a problem with Imager or my script, I get the same results whatever script I try. Could it be that my perl installation lacks debugging support? root@emilia:/root/.cpan/build/Imager-0.51# gdb perl GNU gdb 6.3-debian [...] (gdb) r -Mblib bug.pl Starting program: /usr/bin/perl -Mblib bug.pl Failed to read a valid object file image from memory. (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) [Thread debugging using libthread_db enabled] Error while reading shared library symbols: Cannot find new threads: generic error (no debugging symbols found) (no debugging symbols found) (no debugging symbols found)
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #20403] Imager crashes when rendering non-antialiased text containing spaces
Date: Tue, 11 Jul 2006 23:14:36 +1000
To: Guest via RT <bug-Imager [...] rt.cpan.org>
From: Tony Cook <tony [...] develop-help.com>
On Tue, Jul 11, 2006 at 07:20:42AM -0400, Guest via RT wrote: Show quoted text
> > Queue: Imager > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=20403 > > > I installed Imager 0.51 via CPAN and tested with different fonts, but the problem remains. >
> > If you have the time, could you please produce a backtrace of the crash?
> > I'm not very good at this, unfortunately. I can't even get gdb to work (see results below). > Seems that this it is not a problem with Imager or my script, I get the same results whatever > script I try. Could it be that my perl installation lacks debugging support? > > root@emilia:/root/.cpan/build/Imager-0.51# gdb perl > GNU gdb 6.3-debian > [...] > (gdb) r -Mblib bug.pl > Starting program: /usr/bin/perl -Mblib bug.pl > Failed to read a valid object file image from memory. > (no debugging symbols found) > (no debugging symbols found) > (no debugging symbols found) > [Thread debugging using libthread_db enabled] > Error while reading shared library symbols: > Cannot find new threads: generic error > (no debugging symbols found) > (no debugging symbols found) > (no debugging symbols found)
Did this end up back at a gdb prompt or return to the shell? The messages about missing debugging symbols are normal, as long as you have them in Imager I'll at least have some information about where the problem is, if it's in Imager. Here's an example session with gdb, I extracted 0.51_02 and modified the low level text output function to crash as a demo: tony@develop-help:~/src/Imager-0.51_02$ gdb perl GNU gdb 6.3-debian Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-linux"...(no debugging symbols found) Using host libthread_db library "/lib/libthread_db.so.1". (gdb) r -Mblib ~/play/imfontcrash.pl test Starting program: /usr/bin/perl -Mblib ~/play/imfontcrash.pl test (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) [Thread debugging using libthread_db enabled] [New Thread 16384 (LWP 2508)] (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) (no debugging symbols found) Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 16384 (LWP 2508)] i_tt_text (handle=0x83bf0f0, im=0x82f0e00, xb=50, yb=50, cl=0x821fa08, points=8, txt=0x8253378 "test", len=4, smooth=0, utf8=0, align=1) at font.c:1680 1680 *(char *)0 = 1; (gdb) bt #0 i_tt_text (handle=0x83bf0f0, im=0x82f0e00, xb=50, yb=50, cl=0x821fa08, points=8, txt=0x8253378 "test", len=4, smooth=0, utf8=0, align=1) at font.c:1680 #1 0x40252156 in XS_Imager_i_tt_text (my_perl=0x814bf18, cv=0x8291a78) at Imager.xs:2034 #2 0x080c3276 in Perl_pp_entersub () #3 0x080bbd69 in Perl_runops_standard () #4 0x080635e8 in perl_run () #5 0x080633f5 in perl_run () #6 0x0805fb9f in main () (gdb) Tony
Subject: strace
From: Erik
I didn't get gdb working, but I ran my script through strace. The result is attached to this message. ok.txt is the result of a succeded test run (trying to print "text") error.txt is the result of a crashing test run (trying to print "text " (note the space))

Message body is not shown because it is too large.

Message body is not shown because it is too large.

Subject: Sorry
From: Erik
Show quoted text
> The result is attached to this message.
Oups, the attachments was added plain text in the email. Sorry about that. But they seem to be downloadable separately from this website. Hope the traces are of use to you, and thank you for developing such a great product as Imager! It is really a great module!
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #20403] strace
Date: Thu, 13 Jul 2006 13:29:17 +1000
To: Guest via RT <bug-Imager [...] rt.cpan.org>
From: Tony Cook <tony [...] develop-help.com>
On Wed, Jul 12, 2006 at 08:07:43PM -0400, Guest via RT wrote: Show quoted text
> > Queue: Imager > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=20403 > > > I didn't get gdb working, but I ran my script through strace. > > The result is attached to this message. > ok.txt is the result of a succeded test run (trying to print "text") > error.txt is the result of a crashing test run (trying to print "text " (note the space))
I've isolated the problem, it appears to be a bug in freetype. If you render a space in mono mode it crashes, or in freetype 2.2 it returns an error. I'll work around this by not rendering glyphs with a width of zero (ie. that draw nothing). Tony
Hi, I've fixed this bug in svn, I've included the patch, which applies enough against 0.44 to fix the bug if you want to use such an old release. It fails to patch the test script, but that's changed a lot since 0.44. This fix will go out with 0.52, probably next week. Tony
Index: freetyp2.c =================================================================== --- freetyp2.c (revision 1033) +++ freetyp2.c (working copy) @@ -693,55 +693,57 @@ slot = handle->face->glyph; gm = &slot->metrics; - error = FT_Render_Glyph(slot, aa ? ft_render_mode_normal : ft_render_mode_mono); - if (error) { - ft2_push_message(error); - i_push_errorf(0, "rendering glyph 0x%04X (character \\x%02X)"); - return 0; - } - if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) { - bmp = slot->bitmap.buffer; - for (y = 0; y < slot->bitmap.rows; ++y) { - int pos = 0; - int bit = 0x80; - for (x = 0; x < slot->bitmap.width; ++x) { - if (bmp[pos] & bit) - i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, cl); - - bit >>= 1; - if (bit == 0) { - bit = 0x80; - ++pos; - } - } - bmp += slot->bitmap.pitch; + if (gm->width) { + error = FT_Render_Glyph(slot, aa ? ft_render_mode_normal : ft_render_mode_mono); + if (error) { + ft2_push_message(error); + i_push_errorf(0, "rendering glyph 0x%04X (character \\x%02X)"); + return 0; } - } - else { - /* grey scale or something we can treat as greyscale */ - /* we create a map to convert from the bitmap values to 0-255 */ - if (last_mode != slot->bitmap.pixel_mode - || last_grays != slot->bitmap.num_grays) { - if (!make_bmp_map(&slot->bitmap, map)) - return 0; - last_mode = slot->bitmap.pixel_mode; - last_grays = slot->bitmap.num_grays; + if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) { + bmp = slot->bitmap.buffer; + for (y = 0; y < slot->bitmap.rows; ++y) { + int pos = 0; + int bit = 0x80; + for (x = 0; x < slot->bitmap.width; ++x) { + if (bmp[pos] & bit) + i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, cl); + + bit >>= 1; + if (bit == 0) { + bit = 0x80; + ++pos; + } + } + bmp += slot->bitmap.pitch; + } } - - bmp = slot->bitmap.buffer; - for (y = 0; y < slot->bitmap.rows; ++y) { - for (x = 0; x < slot->bitmap.width; ++x) { - int value = map[bmp[x]]; - if (value) { - i_gpix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel); - for (ch = 0; ch < im->channels; ++ch) { - pel.channel[ch] = - ((255-value)*pel.channel[ch] + value * cl->channel[ch]) / 255; - } - i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel); - } - } - bmp += slot->bitmap.pitch; + else { + /* grey scale or something we can treat as greyscale */ + /* we create a map to convert from the bitmap values to 0-255 */ + if (last_mode != slot->bitmap.pixel_mode + || last_grays != slot->bitmap.num_grays) { + if (!make_bmp_map(&slot->bitmap, map)) + return 0; + last_mode = slot->bitmap.pixel_mode; + last_grays = slot->bitmap.num_grays; + } + + bmp = slot->bitmap.buffer; + for (y = 0; y < slot->bitmap.rows; ++y) { + for (x = 0; x < slot->bitmap.width; ++x) { + int value = map[bmp[x]]; + if (value) { + i_gpix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel); + for (ch = 0; ch < im->channels; ++ch) { + pel.channel[ch] = + ((255-value)*pel.channel[ch] + value * cl->channel[ch]) / 255; + } + i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel); + } + } + bmp += slot->bitmap.pitch; + } } } Index: t/t38ft2font.t =================================================================== --- t/t38ft2font.t (revision 1033) +++ t/t38ft2font.t (working copy) @@ -1,7 +1,7 @@ #!perl -w use strict; use lib 't'; -use Test::More tests => 158; +use Test::More tests => 160; ++$|; # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' @@ -19,13 +19,13 @@ SKIP: { - i_has_format("ft2") or skip("no freetype2 library found", 157); + i_has_format("ft2") or skip("no freetype2 library found", 159); print "# has ft2\n"; my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf'; - -f $fontname or skip("cannot find fontfile $fontname", 157); + -f $fontname or skip("cannot find fontfile $fontname", 159); my $bgcolor=i_color_new(255,0,0,0); @@ -399,6 +399,19 @@ } ok($im->write(file=>'testout/t38align.ppm'), "save align image"); } + + + { # outputting a space in non-AA could either crash + # or fail (ft 2.2+) + my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2'); + my $im = Imager->new(xsize => 100, ysize => 100); + ok($im->string(x => 10, y => 10, string => "test space", aa => 0, + color => '#FFF', size => 8, font => $font), + "draw space non-antialiased (color)"); + ok($im->string(x => 10, y => 50, string => "test space", aa => 0, + channel => 0, size => 8, font => $font), + "draw space non-antialiased (channel)"); + } } sub align_test { @@ -440,7 +453,6 @@ else { SKIP: { skip("couldn't draw text", 7) }; } - } sub okmatchcolor {
Subject: Version
From: Erik
Show quoted text
> I've fixed this bug in svn, I've included the patch, which applies > enough against 0.44 to fix the bug if you want to use such an old > release. It fails to patch the test script, but that's changed a lot > since 0.44.
The only reason I used 0.44 was that it was the current debian version (libimager-perl). I uninstalled the debian package and installed 0.51 from CPAN instead. Show quoted text
> This fix will go out with 0.52, probably next week.
With my level of knowledge of linux, it would take about a week to apply the patch and rebuild Imager :-) So I think I will wait for the 0.52 release instead!
On Thu Jul 13 19:27:48 2006, guest wrote: Show quoted text
> With my level of knowledge of linux, it would take about a week to > apply the patch and > rebuild Imager :-) So I think I will wait for the 0.52 release > instead!
I've had some other bugs reported that will delay 0.52. These are old bugs rather than problems introduced recently. Your fix is included in 0.51_03 though. Tony
Hi, this problem has been fixed in Imager 0.52, released today. If you have any further problems with this issue please reply to this message. Thanks for your help with this. Tony