• 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
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
plugin Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...