etcd icon indicating copy to clipboard operation
etcd copied to clipboard

fix(pkg/ioutil):avoid panic in PageWriter.Write() when pageBytes is 0

Open secsys-go opened this issue 3 years ago • 6 comments

pkg/ioutil: add check for pageBytes when creating PageWriter

NewPageWriter() without check could return a PageWriter whose pageBytes is equal to 0. This is fatal when buffer to write is longer than defaultBufferBytes, and it will crashed in PageWriter.Write() with: "panic: runtime error: integer divide by zero". This check will prevent creating PageWriter in NewPageWriter()when pageBytes is 0, and return a nil at that time.

secsys-go avatar May 09 '22 05:05 secsys-go

Codecov Report

Merging #14022 (29d30ab) into main (b7be91f) will increase coverage by 0.02%. The diff coverage is 62.50%.

:exclamation: Current head 29d30ab differs from pull request most recent head 76112f1. Consider uploading reports for the commit 76112f1 to get more accurate results

@@            Coverage Diff             @@
##             main   #14022      +/-   ##
==========================================
+ Coverage   75.00%   75.03%   +0.02%     
==========================================
  Files         450      446       -4     
  Lines       37173    36723     -450     
==========================================
- Hits        27882    27555     -327     
+ Misses       7522     7432      -90     
+ Partials     1769     1736      -33     
Flag Coverage Δ
all 75.03% <62.50%> (+0.02%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
etcdctl/ctlv3/command/watch_command.go 44.08% <0.00%> (ø)
server/etcdmain/etcd.go 41.25% <25.00%> (-4.12%) :arrow_down:
server/etcdmain/config.go 86.12% <71.42%> (+0.85%) :arrow_up:
etcdctl/ctlv3/command/txn_command.go 63.15% <100.00%> (-4.39%) :arrow_down:
etcdctl/ctlv3/command/util.go 17.97% <100.00%> (ø)
client/pkg/v3/verify/verify.go 88.46% <0.00%> (-11.54%) :arrow_down:
server/proxy/grpcproxy/register.go 81.39% <0.00%> (-9.31%) :arrow_down:
server/auth/simple_token.go 80.00% <0.00%> (-8.47%) :arrow_down:
server/etcdserver/api/v3lock/lock.go 61.53% <0.00%> (-8.47%) :arrow_down:
etcdctl/ctlv3/command/printer_simple.go 53.08% <0.00%> (-8.03%) :arrow_down:
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b7be91f...76112f1. Read the comment docs.

codecov-commenter avatar May 13 '22 10:05 codecov-commenter

Please also rebase this PR.

ahrtr avatar May 13 '22 11:05 ahrtr

@secsys-go Please update this PR per the comment.

ahrtr avatar May 18 '22 02:05 ahrtr

Please squash the commits.

ahrtr avatar May 23 '22 06:05 ahrtr

Again, please squash the commits into just one commit. FYI. git-squash

ahrtr avatar May 24 '22 07:05 ahrtr

This is the squashed one:dc559c17979a1823fab7c80478c74b4db28e0f1b

secsys-go avatar Jun 13 '22 04:06 secsys-go

Since there is no response from the author for a long time, so I resolved it in https://github.com/etcd-io/etcd/pull/14452

ahrtr avatar Sep 13 '22 11:09 ahrtr