[ISSUE #10776] Handle short HTTP2 protocol buffers - #10777
Conversation
There was a problem hiding this comment.
Pull request overview
Improves robustness of the proxy’s HTTP/2 protocol detection by preventing Http2ProtocolProxyHandler.match() from throwing on empty/short Netty ByteBuf inputs, and adds regression tests to cover those boundary cases.
Changes:
- Add a
readableBytes() >= 4guard before reading the HTTP/2PRIprefix as anint. - Add unit tests covering empty buffers, short buffers (<4 bytes), and the valid
PRIprefix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| proxy/src/main/java/org/apache/rocketmq/proxy/remoting/protocol/http2proxy/Http2ProtocolProxyHandler.java | Adds a short-buffer guard to avoid IndexOutOfBoundsException during HTTP/2 detection. |
| proxy/src/test/java/org/apache/rocketmq/proxy/remoting/protocol/http2proxy/Http2ProtocolProxyHandlerTest.java | Adds regression coverage for short/empty buffers and the PRI HTTP/2 preface prefix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Before | ||
| public void setUp() throws Exception { | ||
| ConfigurationManager.initConfig(); | ||
| ConfigurationManager.getProxyConfig().setEnableRemotingLocalProxyGrpc(true); | ||
| http2ProtocolProxyHandler = new Http2ProtocolProxyHandler(); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #10777 +/- ##
=============================================
- Coverage 48.24% 48.22% -0.02%
+ Complexity 13496 13489 -7
=============================================
Files 1380 1380
Lines 101104 101106 +2
Branches 13107 13108 +1
=============================================
- Hits 48773 48761 -12
- Misses 46350 46356 +6
- Partials 5981 5989 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Adds a readable-bytes check in Http2ProtocolDecoder.decode() to ensure the buffer has at least 4 bytes before calling in.getInt(), preventing IndexOutOfBoundsException on short buffers.
Findings
- [Info] The fix is correct. Checking
in.readableBytes() < 4and returningnullto signal "need more data" is the standard Netty pattern for protocol decoders. - [Info] Test coverage is good —
testDecodeShortBufferRejectverifies rejection of short buffers, andtestDecodeHttp2PrefacePrefixverifies valid HTTP/2 preface detection still works.
Suggestions
- None. Clean, minimal fix with proper test coverage.
LGTM.
Automated review by github-manager-bot
What changed
falsefromHttp2ProtocolProxyHandler.match()when fewer than 4 readable bytes are available.PRIprefix.Fixes #10776.
Verification
mvn -pl proxy -Dtest=Http2ProtocolProxyHandlerTest testResult: BUILD SUCCESS.
Http2ProtocolProxyHandlerTestran 3 tests with 0 failures, errors, or skips. Checkstyle and SpotBugs also passed in the Maven run.