Security Advisories (9)
CVE-2016-1238 (2016-08-02)

Imager would search the default current directory entry in @INC when searching for file format support modules.

CVE-2008-1928 (2008-04-24)

Buffer overflow in Imager 0.42 through 0.63 allows attackers to cause a denial of service (crash) via an image based fill in which the number of input channels is different from the number of output channels.

CVE-2007-2459 (2007-05-02)

Heap-based buffer overflow in the BMP reader (bmp.c) in Imager perl module (libimager-perl) 0.45 through 0.56 allows remote attackers to cause a denial of service (application crash) and possibly execute arbitrary code via crafted 8-bit/pixel compressed BMP files.

CPANSA-Imager-2014-01 (2014-01-03)

When drawing on an image with an alpha channel where the source minimum is greater than zero, Imager would read from beyond the end of a malloc() allocated buffer. In rare circumstances this could lead to some of the source image not being written to the target image, or possibly to a segmentation fault.

CVE-2024-53901 (2024-11-17)

"invalid next size" backtrace on use of trim on certain images

CVE-2006-0053 (2006-04-10)

Imager (libimager-perl) before 0.50 allows user-assisted attackers to cause a denial of service (segmentation fault) by writing a 2- or 4-channel JPEG image (or a 2-channel TGA image) to a scalar, which triggers a NULL pointer dereference.

CVE-2026-8669 (2026-05-15)

Imager versions through 1.030 for Perl allow a heap out of bounds (OOB) write on crafted multi-frame GIF files. Imager::File::GIF's i_readgif_multi_low allocates a single per-row buffer GifRow sized for the GIF's global screen width 'SWidth' and reuses it across every image in the file. The page-match branch validates Image.Width + Image.Left > SWidth before each DGifGetLine write, but the parallel skip-image branch at imgif.c:790-805 calls DGifGetLine(GifFile, GifRow, Width) with no such check.

CVE-2026-13705 (2026-07-06)

Imager versions before 1.032 for Perl have a heap out-of-bounds read in the bundled Imager::File::SGI reader via a 16-bit RLE literal run in read_rgb_16_rle. read_rgb_16_rle guards each literal run with if (count > data_left), but count is a pixel count while every 16-bit sample consumes two bytes. The copy loop reads inp[0] * 256 + inp[1] and advances two bytes per pixel, so a run with data_left / 2 < count <= data_left passes the guard yet consumes 2 * count bytes and reads past the end of the buffer. The 8-bit path is unaffected because there one pixel is one byte. Reading a crafted SGI image through Imager->read triggers the over-read before the parser rejects the malformed image, which can crash the process.

CVE-2026-14454 (2026-07-08)

Imager versions before 1.033 for Perl treat unsigned EXIF IFD entry counts as signed. Imager mishandled large EXIF IFD entry count values, treating them as negative numbers. This could lead to an attempt to allocate a block nearly the size of the address space, which fails and kills the process. An attacker could craft an image with EXIF data that terminates a worker process.

NAME

Imager::Font::Wrap - simple wrapped text output

SYNOPSIS

use Imager::Font::Wrap;

my $img = Imager->new(xsize=>$xsize, ysize=>$ysize);

my $font = Imager::Font->new(file=>$fontfile);

my $string = "..."; # text with or without newlines

Imager::Font::Wrap->wrap_text( image  => $img,
                               font   => $font,
                               string => $string,
                               x      => $left,
                               y      => $top,
                               width  => $width,
                               .... );

DESCRIPTION

This is a simple text wrapper with options to control the layout of text within the line.

You can control the position, width and height of the text with the image, x, y, width and height options.

You can simply calculate space usage by setting image to undef, or set savepos to see how much text can fit within the given height.

OPTIONS

x
y

The top-left corner of the rectangle the text is formatted into. Defaults to (0, 0).

width

The width of the formatted text in pixels. Defaults to the horizontal gap between the top-left corner and the right edge of the image. If no image is supplied then this is required.

height

The maximum height of the formated text in pixels. Not required.

savepos

The amount of text consumed (as a count of characters) will be stored into the scalar this refers to.

my $pagenum = 1;
my $string = "...";
my $font = ...;
my $savepos;

while (length $string) { 
  my $img = Imager->new(xsize=>$xsize, ysize=>$ysize);
  Imager::Font::Wrap->wrap_text(string=>$string, font=>$font, 
                                image=>$img, savepos => \$savepos)
    or die $img->errstr;
  $savepos > 0
    or die "Could not fit any text on page\n";
  $string = substr($string, $savepos);
  $img->write(file=>"page$pagenum.ppm");
}
image

The image to render the text to. Can be supplied as undef to simply calculate the bounding box.

font

The font used to render the text. Required.

size

The size to render the font in. Defaults to the size stored in the font object. Required if it isn't stored in the font object.

string

The text to render. This can contain non-whitespace, blanks (ASCII 0x20), and newlines.

Newlines must match /(?:\x0A\x0D?|\x0D\x0A?)/. Whitespace other than blanks and newlines are completely ignored.

justify

The way text is formatted within each line. Possible values include:

left

Left aligned against the left edge of the text box.

Right aligned against the right edge of the text box.

center

Centered horizontally in the text box.

fill

All but the final line of the paragraph has spaces expanded so that the line fills from the left to the right edge of the text box.

linegap

Gap between lines of text in pixels. This is in addition to the size from $font->font_height. Can be positive or negative. Default 0.

Any other parameters are passed onto Imager::Font->draw().

RETURNS

Returns a list:

($left, $top, $right, $bottom)

which are the bounds of the space used to layout the text.

If height is set then this is the space used within that height.

You can use this to calculate the space required to format the text before doing it:

my ($left, $top, $right, $bottom) =
  Imager::Font::Wrap->wrap_text(string => $string,
                                font   => $font,
                                width  => $xsize);
my $img = Imager->new(xsize=>$xsize, ysize=>$bottom);
Imager::Font::Wrap->wrap_text(string => $string,
                              font   => $font,
                              width  => $xsize,
                              image  => $image);

BUGS

Imager::Font can handle UTF8 encoded text itself, but this module doesn't support that (and probably won't). This could probably be done with regex magic.

Currently ignores the sizew parameter, if you supply one it will be supplied to the draw() function and the text will be too short or too long for the width.

Uses a simplistic text model, which is why there's no hyphenation, and no tabs.

AUTHOR

Tony Cook <tony@develop-help.com>

SEE ALSO

Imager(3), Imager::Font(3)