Starting in Tk 8.6.5, the following code snippet produces an invalid PNG file:

<pre>
########
# create image (large dimensions seem to trigger the bug)
set width 2000
set height 5000
set img [image create photo -width $width -height $height]

# create row of random RGB pixels (a high number of different colors seems to be requirement for the bug)
set row {}
for {set x 0} {$x < $width} {incr x} {
    set c [format "#%02X%02X%02X" [expr int(rand() * 256)] [expr int(rand() * 256)] [expr int(rand() * 256)]]
    lappend row $c
}
set row [list $row]

# fill image with 'row'
for {set y 0} {$y < $height} {incr y} {
    $img put $row -to 0 $y $width [expr {$y + 1}]
}

# write png
set fname
$img write -format png $fname

exit
########
</pre>


Loading with a libpng-based app (e.g. pngtopnm), results in several error messages, such as

<pre>
...
libpng warning: Ignoring bad adaptive filter type
libpng warning: Ignoring bad adaptive filter type
pnmtopng:  fatal libpng error: Extra compressed data
pngtopnm: setjmp returns error condition
</pre>