Repository navigation
fix: prevent decoder crashes on unhashable map keys and deep nesting (v2) - #140
Merged
Merged
Conversation
Untrusted MessagePack input could crash the process in two ways: - A map key decoded as bin (or as an unhashable ext value) panicked with "hash of unhashable type". canSetAsMapKey now rejects Bin8/Bin16/Bin32, and the reflect map path checks interface keys before SetMapIndex. Ext-decoded keys are checked for hashability. - Unbounded recursion on nested arrays/maps/structs caused a fatal, unrecoverable stack overflow. Decoding now tracks nesting depth and returns ErrExceededMaxDepth beyond 10000 levels. Both the buffer and stream decoders are fixed. New errors: ErrCanNotSetBinAsMapKey, ErrUnhashableMapKey, ErrExceededMaxDepth. Benchmarks show no significant regression and no change in B/op or allocs/op.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## v2 #140 +/- ##
==========================================
- Coverage 98.35% 98.08% -0.27%
==========================================
Files 73 74 +1
Lines 5880 5993 +113
==========================================
+ Hits 5783 5878 +95
- Misses 56 67 +11
- Partials 41 48 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
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
maininterface{}map keys instead of panickingBackground / Motivation
Same issues as on v3: a bin map key panicked, and deeply nested input caused an unrecoverable stack overflow. The v2 decoders share the same structure, so the fix is ported with minimal adaptation.
Changes
main, for both buffer and stream decoderssetStructErrCanNotSetBinAsMapKey,ErrUnhashableMapKey,ErrExceededMaxDepthTest Plan
go vet ./.../go test -race ./...passmainv2: geomean +0.8%; B/op and allocs/op unchanged