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 authored and jholdstock committed Sep 12, 2023
1 parent 042cf24 commit a757fd3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pool/boltupgrades_test.go
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 a757fd3

Please sign in to comment.