Commit 1ec3ac70 authored by ROOL's avatar ROOL 🤖
Browse files

Fixes for failure to export some sprites as PNG

Detail:
  Buffer overflow fix for certain 24bpp + alpha sprites
  Ref: https://www.riscosopen.org/forum/forums/8/topics/2146?page=24#posts-121254
  Attempt to write invalid output when 8bpp paletted + alpha sprite, 8bpp with per-pixel
  alpha is not a combination PNG allows, so this is now upscaled to 24bpp + alpha first
  Ref: https://www.riscosopen.org/forum/forums/5/topics/16425?page=1#posts-121264
Admin:
  Submission for PNG bounty.

Version 2.40. Tagged as 'Paint-2_40'
parent f7532fe3
......@@ -9,12 +9,12 @@
GBLS Module_ApplicationDate
GBLS Module_HelpVersion
GBLS Module_ComponentName
Module_MajorVersion SETS "2.39"
Module_Version SETA 239
Module_MajorVersion SETS "2.40"
Module_Version SETA 240
Module_MinorVersion SETS ""
Module_Date SETS "21 Apr 2021"
Module_ApplicationDate SETS "21-Apr-21"
Module_Date SETS "01 May 2021"
Module_ApplicationDate SETS "01-May-21"
Module_ComponentName SETS "Paint"
Module_FullVersion SETS "2.39"
Module_HelpVersion SETS "2.39 (21 Apr 2021)"
Module_FullVersion SETS "2.40"
Module_HelpVersion SETS "2.40 (01 May 2021)"
END
/* (2.39)
/* (2.40)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 2.39
#define Module_MajorVersion_CMHG 2.40
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 21 Apr 2021
#define Module_Date_CMHG 01 May 2021
#define Module_MajorVersion "2.39"
#define Module_Version 239
#define Module_MajorVersion "2.40"
#define Module_Version 240
#define Module_MinorVersion ""
#define Module_Date "21 Apr 2021"
#define Module_Date "01 May 2021"
#define Module_ApplicationDate "21-Apr-21"
#define Module_ApplicationDate "01-May-21"
#define Module_ComponentName "Paint"
#define Module_FullVersion "2.39"
#define Module_HelpVersion "2.39 (21 Apr 2021)"
#define Module_LibraryVersionInfo "2:39"
#define Module_FullVersion "2.40"
#define Module_HelpVersion "2.40 (01 May 2021)"
#define Module_LibraryVersionInfo "2:40"
......@@ -191,7 +191,7 @@ static int export_find_palette_hole(export_info *info)
mask = ((char *)src) + src->mask + y * info->maskstride;
for (xsrc = info->sprite_lbit, mask_xsrc = info->lbit;
xsrc <= info->sprite_rbit;
xsrc < info->sprite_rbit;
xsrc += info->sprite_pixbpp, mask_xsrc += info->bpp)
{ maskdata = *(mask + xsrc / 8);
maskdata = (maskdata >> (xsrc & 7)) & mask_piece;
......@@ -399,7 +399,7 @@ static void export_fill_rowbuffer(export_info *info, const int rownum)
{ case pngdata_rgba:
case pngdata_rgb:
/* source needs mapping to 24 bit RGB */
for (xsrc = info->sprite_lbit, xdst = 0; xsrc <= info->sprite_rbit; xsrc += info->sprite_pixbpp, xdst += info->pixwidth)
for (xsrc = info->sprite_lbit, xdst = 0; xsrc < info->sprite_rbit; xsrc += info->sprite_pixbpp, xdst += info->pixwidth)
{
switch (info->sprite_type) {
case sprtype_8888_tbgr:
......@@ -464,7 +464,7 @@ static void export_fill_rowbuffer(export_info *info, const int rownum)
case pngdata_p:
case pngdata_pa:
/* source is <=8bpp and needs mapping to a single byte palette value */
for (xsrc = info->sprite_lbit, xdst = 0; xsrc <= info->sprite_rbit; xsrc += info->sprite_pixbpp, xdst += info->pixwidth)
for (xsrc = info->sprite_lbit, xdst = 0; xsrc < info->sprite_rbit; xsrc += info->sprite_pixbpp, xdst += info->pixwidth)
{ int pix;
pix = *(rowpixels + xsrc / 8);
pix = (pix >> (xsrc & 7)) & pixmask;
......@@ -477,7 +477,7 @@ static void export_fill_rowbuffer(export_info *info, const int rownum)
/* source is greyscaled */
/* look up the palette entry and output the appropriate grey level for it */
/* source will be <= 8bpp */
for (xsrc = info->sprite_lbit, xdst = 0; xsrc <= info->sprite_rbit; xsrc += info->sprite_pixbpp, xdst += info->pixwidth)
for (xsrc = info->sprite_lbit, xdst = 0; xsrc < info->sprite_rbit; xsrc += info->sprite_pixbpp, xdst += info->pixwidth)
{ int pix;
pix = *(rowpixels + xsrc / 8);
pix = (pix >> (xsrc & 7)) & pixmask;
......@@ -498,7 +498,7 @@ static void export_fill_rowbuffer(export_info *info, const int rownum)
char data;
mask += info->maskstride * rownum; /* move to the current line */
for (xsrc = info->lbit, xdst = 0; xsrc <= info->rbit; xsrc += info->bpp, xdst += info->pixwidth)
for (xsrc = info->lbit, xdst = 0; xsrc < info->rbit; xsrc += info->bpp, xdst += info->pixwidth)
{ data = *(mask + xsrc / 8);
data = (data >> (xsrc & 7)) & mask_piece;
......@@ -749,8 +749,11 @@ static int export_png_start(export_info *info)
if (c->flags & CompressPNG_Flags_Greyscale)
info->rowtype = info->masktype != transparency_type_none ? pngdata_ga : pngdata_g;
else
info->rowtype = info->masktype != transparency_type_none ? pngdata_rgba : pngdata_rgb;
{ info->rowtype = info->masktype != transparency_type_none ? pngdata_rgba : pngdata_rgb;
/* if we happened to end up here because (eg) a 4bpp image has a full alpha channel
we will have the wrong pixel width for the output row */
info->pixwidth = info->rowtype == pngdata_rgba ? 4 : 3;
}
c->parameter[PNG_PARAM_PALETTE].parameter = png_param_end_of_list;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment