Skip to content

Validate decoded fields in GobDecode to prevent nil noise, invalid bounds, and division by zero#404

Open
AndyBurecovics wants to merge 1 commit intogoogle:mainfrom
AndyBurecovics:fix/gobdecode-validation
Open

Validate decoded fields in GobDecode to prevent nil noise, invalid bounds, and division by zero#404
AndyBurecovics wants to merge 1 commit intogoogle:mainfrom
AndyBurecovics:fix/gobdecode-validation

Conversation

@AndyBurecovics
Copy link
Copy Markdown

GobDecode functions in the dpagg package do not validate deserialized fields, allowing crafted payloads to produce aggregation objects that panic or return incorrect results on Result().

This patch adds post-decode validation mirroring the checks already enforced by constructors:

  • NoiseKind maps to a valid Noise implementation (prevents nil pointer dereference)
  • Epsilon, delta, sensitivities pass the same range checks as New*() constructors
  • Bounds satisfy lower < upper (prevents division by zero in clamping)
  • TreeHeight and BranchingFactor are positive (prevents division by zero in quantile tree)

A new helper file gobdecode_checks.go centralizes the common validation logic.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 13, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@AndyBurecovics AndyBurecovics force-pushed the fix/gobdecode-validation branch from 4ba1513 to bcb8e03 Compare April 13, 2026 17:01
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to move this to go/checks/ directory.

Comment thread go/dpagg/sum.go
if err != nil {
return fmt.Errorf("couldn't decode BoundedSumFloat64 from bytes")
}
nObj2, err := validateDecodedAggregation(enc.Epsilon, enc.Delta, enc.LInfSensitivity, enc.L0Sensitivity, enc.NoiseKind)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nObj2 -> nObj

Comment thread go/dpagg/mean.go
if err != nil {
return fmt.Errorf("couldn't decode BoundedMean from bytes")
}
if err := checks.CheckBoundsFloat64(enc.Lower, enc.Upper); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For mean & variance, I think we could call validateDecodedAggregation on the underlying Count and Sum objects for completeness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants