Limit recursion depth and bump dependencies#2405
Open
hdm wants to merge 4 commits into
Open
Conversation
Signed-off-by: HD Moore <x@hdm.io>
Signed-off-by: HD Moore <x@hdm.io>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a maximum BSON document nesting depth (100) to the value reader to prevent unbounded recursion when decoding deeply nested BSON, with accompanying tests. Also bumps the Go toolchain and several dependency versions.
Changes:
- Track per-frame nesting depth in
valueReaderand returnerrMaxDocumentNestingDepthfromReadDocument,ReadArray, andReadCodeWithScopewhen depth exceeds 100. - Add tests verifying that overly nested documents and arrays are rejected.
- Bump
godirective to 1.25.0 and upgradeklauspost/compress,golang.org/x/crypto,golang.org/x/sync, andgolang.org/x/text.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| bson/value_reader.go | Adds depth field to vrState, depth-check helper, and threads depth through container/element/value reads. |
| bson/unmarshal_test.go | Adds two tests for rejecting over-deep document and array nesting. |
| go.mod | Bumps minimum Go version to 1.25.0 and upgrades several dependencies. |
| go.sum | Adds checksums for upgraded dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: HD Moore <x@hdm.io>
Signed-off-by: HD Moore <x@hdm.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR addresses two issues:
Background & Motivation
A review of the mongo-db-driver found that deeply nested BSON could consume excess resources and trigger a stack overflow. Upon creating the PR, GH complained about the dependencies being out of date.