snappy/s2: Limit length of varint in decodedLen - #1148
Conversation
To match C++ implementation
📝 WalkthroughWalkthroughThis PR tightens varint length validation in the snapref and s2 decoders to reject overlong varint preambles (consuming >5 bytes). ChangesVarint Length Validation
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The go version uses the same mechanism. I don't really see any reason to change it. If people want to waste bytes IMO they are free to do so. |
|
I'll update go version soon (need to unarchive repo first). The purpose is consistency: we want all decoders to produce the same output from the same input. The "golden" behavior is the one from C++ implementation. There we decode only until "offset" is less than 32 (given 7-bit increment that is up to 5 bytes). In brotli we have even more strict check that disallows leading zero nibs, but I can imagine some hardware encoder might prefer to have fixed size preamble if the stream length is unknown upfront, so checking for leading zeros would be harmful for snappy. Yes, that is not exactly what spec says; going to update it to clarify that as well. |
klauspost
left a comment
There was a problem hiding this comment.
OK. I will revert at the first sign of problems.
decodedLendecodedLen
To save others arriving here from finding the related changes; PR (pending) is here; |
|
Will poke the owner soon. |
|
It has been released as part of https://github.com/klauspost/compress/releases/tag/v1.19.0 |
To match C++ implementation.
Summary by CodeRabbit
Bug Fixes
Tests