Fix duplicate tIME chunk from png_write_png

Also add an example program, pngcp.c, which illustrates the problem when used to
copy pngtest.png (the result is an invalid PNG because the tIME chunk is
duplicated.)

Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
John Bowler
2015-12-18 14:42:29 -08:00
parent c75a0a40b4
commit 8d48a512bd
3 changed files with 545 additions and 0 deletions

View File

@@ -2160,6 +2160,12 @@ png_write_tIME(png_structrp png_ptr, png_const_timep mod_time)
return;
}
/* Duplicate tIME chunks are invalid; this works round a bug in png_write_png
* where it would write the tIME chunk once before and once after the IDAT.
*/
if (png_ptr->wrote_tIME)
return;
png_save_uint_16(buf, mod_time->year);
buf[2] = mod_time->month;
buf[3] = mod_time->day;
@@ -2168,6 +2174,7 @@ png_write_tIME(png_structrp png_ptr, png_const_timep mod_time)
buf[6] = mod_time->second;
png_write_complete_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
png_ptr->wrote_tIME = 1U;
}
#endif