Skip to content

Commit 0e83566

Browse files
Merge pull request #1041 from ClickHouse/fix_potential_overflow
fix(compressor): fixing an overflow that could potentially smuggle query in from data
2 parents aadb7ee + b64209f commit 0e83566

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.gitignore

+3
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

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ func (w *Writer) Compress(buf []byte) error {
5656
n = copy(w.Data[headerSize:], buf)
5757
}
5858

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

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

0 commit comments

Comments
 (0)