9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] bug in topng(1)
@ 2012-12-24 14:07 Erik Quanstrom
  2012-12-24 17:45 ` cinap_lenrek
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Quanstrom @ 2012-12-24 14:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



yaroslav <yarikos@gmail.com> wrote:

>There's a bug in topng(1) which under certain circumstances may result in
>broken output image.  When such an image then is fed to png(1)
>diagnostics like the following are produced:
>
>	term% png /tmp/1.png
>	png: unknown filtering scheme 49
>
>(The filtering scheme number may differ.)
>
>This happens when at the beginning of an input line (z->x == 0) there
>are only room for exactly one pixel in output buffer (b+pixwids == e),
>at /sys/src/cmd/jpg/writepng.c:/^zread/+/while/.
>
>Since every scan line should start with a filter algorithm ID it
>consumes a byte in the buffer, leaving no room for the pixel.  The
>"pixels" variable turns zero, no pixels are emitted, yet the alg byte
>slips out.  During next run of zread() with empty buffer, the alg byte
>is emitted again, causing permanent skew of output bytes.
>
>The proposed fix is to modify the loop condition so the loop won't
>proceed if there are not enough room for at least one pixel plus a
>byte for the filter alg ID.
>
>Submitted /n/sources/patch/topng-extrabyte/.
>
>- yk
>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [9fans] bug in topng(1)
@ 2012-12-24 12:27 yaroslav
  0 siblings, 0 replies; 6+ messages in thread
From: yaroslav @ 2012-12-24 12:27 UTC (permalink / raw)
  To: 9fans

There's a bug in topng(1) which under certain circumstances may result in
broken output image.  When such an image then is fed to png(1)
diagnostics like the following are produced:

	term% png /tmp/1.png
	png: unknown filtering scheme 49

(The filtering scheme number may differ.)

This happens when at the beginning of an input line (z->x == 0) there
are only room for exactly one pixel in output buffer (b+pixwids == e),
at /sys/src/cmd/jpg/writepng.c:/^zread/+/while/.

Since every scan line should start with a filter algorithm ID it
consumes a byte in the buffer, leaving no room for the pixel.  The
"pixels" variable turns zero, no pixels are emitted, yet the alg byte
slips out.  During next run of zread() with empty buffer, the alg byte
is emitted again, causing permanent skew of output bytes.

The proposed fix is to modify the loop condition so the loop won't
proceed if there are not enough room for at least one pixel plus a
byte for the filter alg ID.

Submitted /n/sources/patch/topng-extrabyte/.

- yk




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-25 13:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-24 14:07 [9fans] bug in topng(1) Erik Quanstrom
2012-12-24 17:45 ` cinap_lenrek
2012-12-24 20:01   ` erik quanstrom
2012-12-25  1:49     ` cinap_lenrek
2012-12-25 13:39       ` erik quanstrom
  -- strict thread matches above, loose matches on Subject: below --
2012-12-24 12:27 yaroslav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).