Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pngminus/pnm2png.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,19 @@ BOOL do_pnm2png (png_struct *png_ptr, png_info *info_ptr,
if (packed_bitmap)
{
/* row data is as many bytes as can fit width x channels x bit_depth */
row_bytes = (width * channels * bit_depth + 7) / 8;
png_uint_32 pixels = (png_uint_32) (channels * bit_depth);
if (pixels == 0 || width > (0xFFFFFFFFU - 7) / pixels)
return FALSE; /* overflow */
row_bytes = (width * pixels + 7) / 8;
}
else
{
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
png_uint_32 bytes_per_sample = (bit_depth <= 8) ? 1 : 2;
png_uint_32 pixel_bytes = (png_uint_32) channels * bytes_per_sample;
if (pixel_bytes == 0 || width > 0xFFFFFFFFU / pixel_bytes)
return FALSE; /* overflow */
row_bytes = width * pixel_bytes;
}

if ((row_bytes == 0) ||
Expand Down