Skip to content

Commit

Permalink
pool: Do chunked decompress in pool tests.
Browse files Browse the repository at this point in the history
It is not good practice to directly copy from a compressed archive to a
file without chunking as it can lead to uncontrolled allocations should
a file become corrupted.
  • Loading branch information
davecgh committed Sep 12, 2023
1 parent 7ab7fb5 commit 37ffed9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pool/boltupgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"compress/gzip"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -57,11 +58,18 @@ func TestBoltDBUpgrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = io.Copy(fi, r)
fi.Close()
if err != nil {
t.Fatal(err)
for {
_, err = io.CopyN(fi, r, 1024)
if err != nil {
if errors.Is(err, io.EOF) {
break
}

fi.Close()
t.Fatal(err)
}
}
fi.Close()
db, err := openBoltDB(dbPath)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 37ffed9

Please sign in to comment.