• Jed Denlea's avatar
    image/gif: make blockReader a ByteReader, harden tests · 58d7231b
    Jed Denlea authored
    golang.org/cl/37258 was committed to fix issue #16146.
    
    This patch seemed intent to allow at most one dangling byte.  But, as
    implemented, many more bytes may actually slip through.  This is because
    the LZW layer creates a bufio.Reader which will itself consume data
    beyond the end of the LZW stream, and this isn't accounted for anywhere.
    
    This change means to avoid the allocation of the bufio.Reader by making
    blockReader implement io.ByteReader.  Further, it adds a close() method
    which detects extra data in the block sequence.  To avoid any
    regressions with poorly encoded GIFs which may have worked accidentally,
    there are no restrictions on how many extra bytes may exist in the final
    full sub-block that contained LZW data.  If the end of the LZW stream
    happened to align with the end of a sub-block, at most one more
    sub-block with a length of 1 byte may exist before the block terminator.
    
    This change aims to be at least as performant as the prior
    implementation.  But the primary gain is avoiding the allocation of a
    bufio.Reader per frame:
    
    name      old time/op    new time/op    delta
    Decode-8     276µs ± 0%     275µs ± 2%    ~     (p=0.690 n=5+5)
    
    name      old speed      new speed      delta
    Decode-8  55.9MB/s ± 0%  56.3MB/s ± 2%    ~     (p=0.690 n=5+5)
    
    name      old alloc/op   new alloc/op   delta
    Decode-8    49.2kB ± 0%    44.8kB ± 0%  -9.10%  (p=0.008 n=5+5)
    
    name      old allocs/op  new allocs/op  delta
    Decode-8       269 ± 0%       267 ± 0%  -0.74%  (p=0.008 n=5+5)
    
    Change-Id: Iec4f9b895561ad52266313fbc73ec82c070c3349
    Reviewed-on: https://go-review.googlesource.com/68350
    Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
    Reviewed-by: 's avatarNigel Tao <nigeltao@golang.org>
    58d7231b
Name
Last commit
Last update
..
color Loading commit data...
draw Loading commit data...
gif Loading commit data...
internal/imageutil Loading commit data...
jpeg Loading commit data...
png Loading commit data...
testdata Loading commit data...
decode_example_test.go Loading commit data...
decode_test.go Loading commit data...
format.go Loading commit data...
geom.go Loading commit data...
geom_test.go Loading commit data...
image.go Loading commit data...
image_test.go Loading commit data...
names.go Loading commit data...
ycbcr.go Loading commit data...
ycbcr_test.go Loading commit data...