Skip to content

Commit

Permalink
gzhttp: Clamp compression level (#890)
Browse files Browse the repository at this point in the history
Clamp compression levels to valid values.
  • Loading branch information
klauspost authored Nov 28, 2023
1 parent bb3065b commit c4e922d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gzhttp/writer/gzkp/gzkp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func init() {
// poolIndex maps a compression level to its index into gzipWriterPools. It
// assumes that level is a valid gzip compression level.
func poolIndex(level int) int {
if level > gzip.BestCompression {
level = gzip.BestCompression
}
if level < gzip.StatelessCompression {
level = gzip.BestSpeed
}
return level - gzip.StatelessCompression
}

Expand Down
6 changes: 6 additions & 0 deletions gzhttp/writer/gzstd/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func init() {
// poolIndex maps a compression level to its index into gzipWriterPools. It
// assumes that level is a valid gzip compression level.
func poolIndex(level int) int {
if level > gzip.BestCompression {
level = gzip.BestCompression
}
if level < gzip.HuffmanOnly {
level = gzip.BestSpeed
}
return level - gzip.HuffmanOnly
}

Expand Down

0 comments on commit c4e922d

Please sign in to comment.