Any suggestions how to begin debugging this?

The PNG writer code is not written in a way
similar to how I think, and I fear breaking
it further with more random tinkering, and
precious few tests to contain us.

Any way to gain confidence whether the errors
are even in the PNG writer, or whether they're
manifestations of more troubles with zlib-encoded
channels?