Fix: strengthen Input validation and prevent Integer overflows #4449
+24
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of Description
This request introduces several security and robustness improvements across multiple components of the Pyroscope codebase. The changes focus on strengthening input validation, preventing integer overflows, and ensuring safer error handling.
Safe Parsing of Sample Rate (
pkg/ingester/pyroscope/ingest_handler.go
)strconv.Atoi
withstrconv.ParseUint(sr, 10, 32)
to ensure that only values safely representable asuint32
are accepted.Bounds Check for ByteSize (
pkg/og/util/bytesize/bytesize.go
)math.MaxInt64
before converting toByteSize (int64)
.math
where required.Validation for Shards (
pkg/querier/replication.go
)shards
is greater than 0 and does not exceedmath.MaxInt
.shardIdx
is within bounds before being used as an index.Safe Handling of Split Count (
pkg/storegateway/gateway_blocks_http.go
)strconv.Atoi
withstrconv.ParseInt(sc, 10, 32)
and added validation.splitCount
is within[0, math.MaxUint32]
; otherwise, reset to a safe default (0).Validation of Log Entry Buffer Size (
pkg/metastore/fsm/log_entry.go
)len(raw)
.len(raw)
exceeds this threshold, return an error instead of allocating a large buffer.Rationale
These changes improve the overall security and stability of Pyroscope by:
All modifications are scoped to the mentioned files and functions. No external dependencies were added, and the fixes are fully compatible with existing functionality.
Go Language Integer overflow
Making slices, maps and channels