GConverterInputStream: fix an edge case
authorDan Winship <danw@gnome.org>
Wed, 30 May 2012 12:30:27 +0000 (08:30 -0400)
committerDan Winship <danw@gnome.org>
Wed, 30 May 2012 13:02:33 +0000 (09:02 -0400)
commit69e12cd3d56ae43b188a278b807e517961627ada
tree6bff3f4cbd4d27a2b70bfb186596e0b4f33cae59
parent0fd9863abe218c002327ea993089476a793a99e6
GConverterInputStream: fix an edge case

Reading from a GConverterInputStream with both input_buffer and
converted_buffer non-empty would return bogus data (the data from
converted_buffer would essentially get skipped over, though the
returned nread reflected what the count would be if it hadn't been).

This was never noticed before because (a) it can't happen if all of
your reads are at least as large as either the internal buffer size or
the remaining length of the stream (which covers most real-world use),
and (b) it can't happen if all of your reads are 1 byte (which covers
most of tests/converter-test). (And (c) it only happens for some
converters/input streams.) But this was happening occasionally in
libsoup when content-sniffing a gzipped response, because the
SoupContentSnifferStream would first read 512 bytes (to sniff), and
then pass through larger reads after that.

Fixed and added a test to converter-test.

https://bugzilla.gnome.org/show_bug.cgi?id=676478
gio/gconverterinputstream.c
gio/tests/converter-stream.c