Skip to content

Commit b64209f

Browse files
committed
refactor: simplify overflow check
1 parent 05fba0a commit b64209f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
# Editors
18+
.idea/

compress/writer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ func (w *Writer) Compress(m Method, buf []byte) error {
5858
n = copy(w.Data[headerSize:], buf)
5959
}
6060

61-
if n+headerSize > cap(w.Data) {
62-
return errors.New("compressed data exceeds allocated buffer capacity")
63-
} else if uint64(n)+uint64(compressHeaderSize) > math.MaxUint32 {
61+
// security: https://github.com/ClickHouse/ch-go/pull/1041
62+
if uint64(n)+uint64(compressHeaderSize) > math.MaxUint32 {
6463
return errors.New("compressed size overflows uint32")
6564
}
6665

0 commit comments

Comments
 (0)