Skip to content

Commit

Permalink
refactor: simplify overflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Feb 14, 2025
1 parent 05fba0a commit b64209f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Editors
.idea/
5 changes: 2 additions & 3 deletions compress/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ func (w *Writer) Compress(m Method, buf []byte) error {
n = copy(w.Data[headerSize:], buf)
}

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

Expand Down

0 comments on commit b64209f

Please sign in to comment.