1
0
mirror of https://github.com/golang/go synced 2024-11-19 18:44:41 -07:00
go/src/compress
Travis Bischel f1deee0e8c compress/gzip: do not count header bytes written in Write
Before, if an underlying writer errored within 10 bytes (plus any gzip
header metadata), a gzip.Write would erroneously report up to 10 bytes
written that were not actually written of the input slice. This is
especially problematic when the input slice is less than 10 bytes.

The error came from counting the 10 header byte write. If writing the
header is completely successful, the 10 bytes written is overridden by
the flate write with the input slice.

This removes counting the 10 required header bytes, and also changes the
return to use zero until the slice is used.

The old Write could return one byte written when it actually was not.
This is difficult to verify because the smallest input slice is one
byte; a test checking that the input slice was the byte written would be
quite involved. Thankfully, gzip's minimum header write is 10 bytes. If
we test that two bytes are not falsely written, we indirectly cover the
one byte case.

Fixes #24625

Change-Id: I1c1f8cd791e0c4cffc22aa8acd95186582c832ba
Reviewed-on: https://go-review.googlesource.com/103861
Reviewed-by: Joe Tsai <joetsai@google.com>
Run-TryBot: Joe Tsai <joetsai@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-02 20:18:14 +00:00
..
bzip2 compress/bzip2: remove bit-tricks 2018-03-21 21:57:15 +00:00
flate compress/flate: remove non-standard extensions to flate 2017-08-31 03:30:43 +00:00
gzip compress/gzip: do not count header bytes written in Write 2018-04-02 20:18:14 +00:00
lzw compress/lzw: don't follow code == hi if last is invalid. 2017-06-08 01:27:37 +00:00
testdata
zlib compress/gzip, compress/zlib: fix Writer documentation inconsistencies 2018-03-13 20:58:19 +00:00