Skip to content

Commit

Permalink
Merge pull request #1041 from ClickHouse/fix_potential_overflow
Browse files Browse the repository at this point in the history
fix(compressor): fixing an overflow that could potentially smuggle query in from data
  • Loading branch information
SpencerTorres authored Feb 14, 2025
2 parents aadb7ee + b64209f commit 0e83566
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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/
6 changes: 5 additions & 1 deletion compress/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ func (w *Writer) Compress(buf []byte) error {
n = copy(w.Data[headerSize:], buf)
}

w.Data = w.Data[:n+headerSize]
// security: https://github.com/ClickHouse/ch-go/pull/1041
if uint64(n)+uint64(compressHeaderSize) > math.MaxUint32 {
return errors.New("compressed size overflows uint32")
}

w.Data = w.Data[:n+headerSize]
binary.LittleEndian.PutUint32(w.Data[hRawSize:], uint32(n+compressHeaderSize))
binary.LittleEndian.PutUint32(w.Data[hDataSize:], uint32(len(buf)))
h := city.CH128(w.Data[hMethod:])
Expand Down

0 comments on commit 0e83566

Please sign in to comment.