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

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

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-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::IO - Imager's io_layer object.

SYNOPSIS

# Imager supplies Imager::IO objects to various callbacks
my $IO = ...;

my $count = $IO->write($data);
my $count = $IO->read($buffer, $max_count);
my $position = $IO->seek($offset, $whence);
my $status = $IO->close;

DESCRIPTION

Imager uses an abstraction when dealing with image files to allow the same code to work with disk files, in memory data and callbacks.

If you're writing an Imager file handler your code will be passed an Imager::IO object to write to or read from.

METHODS

write

Call to write to the file. Returns the number of bytes written. The data provided may contain only characters \x00 to \xFF - characters outside this range will cause this method to croak().

If you supply a UTF-8 flagged string it will be converted to a byte string, which may have a performance impact.

Returns -1 on error, though in most cases if the result of the write isn't the number of bytes supplied you'll want to treat it as an error anyway.

read
my $buffer;
my $count = $io->read($buffer, $max_bytes);

Reads up to $max_bytes bytes from the current position in the file and stores them in $buffer. Returns the number of bytes read on success or an empty list on failure. Note that a read of zero bytes is not a failure, this indicates end of file.

read2
my $buffer = $io->read2($max_bytes);

An alternative interface to read, that might be simpler to use in some cases.

Returns the data read or an empty list.

seek
my $new_position = $io->seek($offset, $whence);

Seek to a new position in the file. Possible values for $whence are:

  • SEEK_SET - $offset is the new position in the file.

  • SEEK_CUR - $offset is the offset from the current position in the file.

  • SEEK_END - $offset is the offset relative to the end of the file.

Note that seeking past the end of the file may or may not result in an error.

Returns the new position in the file, or -1 on error.

close
my $result = $io->close;

Call when you're with the file. If the IO object is connected to a file this won't close the file handle, but buffers may be flushed (if any).

Returns 0 on success, -1 on failure.

AUTHOR

Tony Cook <tonyc@cpan.org>

SEE ALSO

Imager, Imager::Files