mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng16] Fixed some bugs in ICC profile writing. The code should now accept
all potentially valid ICC profiles and reject obviously invalid ones. It now uses png_error() to do so rather than casually writing a PNG without the necessary color data.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
363ae65e2b
commit
cf49919686
@@ -749,7 +749,10 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
|
||||
params[1], (unsigned long)fake_len);
|
||||
exit(1);
|
||||
}
|
||||
proflen = (png_uint_32)fake_len;
|
||||
proflen = (png_uint_32)(fake_len & ~3U);
|
||||
/* Always fix up the profile length. */
|
||||
png_save_uint_32(profile, proflen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,7 +780,7 @@ insert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,
|
||||
{
|
||||
fprintf(stderr, "--insert iCCP %s: profile length field wrong:\n",
|
||||
params[1]);
|
||||
fprintf(stderr, " actual %lu, recorded value %lu (correted)\n",
|
||||
fprintf(stderr, " actual %lu, recorded value %lu (corrected)\n",
|
||||
(unsigned long)proflen, (unsigned long)prof_header);
|
||||
png_save_uint_32(profile, proflen);
|
||||
}
|
||||
@@ -821,6 +824,20 @@ set_text(png_structp png_ptr, png_infop info_ptr, png_textp text,
|
||||
}
|
||||
break;
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
png_bytep data = NULL;
|
||||
png_size_t fake_len = load_fake(param, &data);
|
||||
|
||||
if (fake_len > 0) /* else a simple parameter */
|
||||
{
|
||||
text->text_length = fake_len;
|
||||
text->text = (png_charp)data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
text->text = param;
|
||||
break;
|
||||
@@ -864,9 +881,9 @@ insert_iTXt(png_structp png_ptr, png_infop info_ptr, int nparams,
|
||||
check_param_count(nparams, 4);
|
||||
clear_text(&text, params[0]);
|
||||
text.compression = 2; /* iTXt + deflate */
|
||||
text.lang = params[2];/* language tag */
|
||||
text.lang_key = params[3]; /* translated keyword */
|
||||
set_text(png_ptr, info_ptr, &text, params[1]);
|
||||
text.lang = params[1];/* language tag */
|
||||
text.lang_key = params[2]; /* translated keyword */
|
||||
set_text(png_ptr, info_ptr, &text, params[3]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -1938,7 +1938,7 @@ static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] =
|
||||
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
}, { /* input: sRGB-rgb+alpha */
|
||||
{ 0, 4, 7, 0 }, { 0, 14, 7, 0 }, { 0, 19, 0, 0 }, { 0, 0, 0, 0 },
|
||||
{ 0, 4, 13, 0 }, { 0, 14, 13, 0 }, { 0, 19, 0, 0 }, { 0, 0, 0, 0 },
|
||||
{ 0, 832, 764, 0 }, { 0, 832, 764, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },
|
||||
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
|
||||
@@ -2013,7 +2013,7 @@ static png_uint_16 gpc_error_via_linear[16][4/*out*/][4] =
|
||||
}, { /* input: sRGB-rgb */
|
||||
{ 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 15, 0 }, { 0, 0, 15, 0 }
|
||||
}, { /* input: sRGB-rgb+alpha */
|
||||
{ 0, 9, 10, 0 }, { 0, 180, 10, 0 }, { 0, 14, 15, 0 }, { 0, 186, 15, 0 }
|
||||
{ 0, 12, 14, 0 }, { 0, 180, 14, 0 }, { 0, 14, 15, 0 }, { 0, 186, 15, 0 }
|
||||
}, { /* input: linear-gray */
|
||||
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
|
||||
}, { /* input: linear-gray+alpha */
|
||||
|
||||
Reference in New Issue
Block a user