Skip to content

[ISSUE #10776] Handle short HTTP2 protocol buffers - #10777

Open
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/proxy-http2-short-buffer
Open

[ISSUE #10776] Handle short HTTP2 protocol buffers#10777
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/proxy-http2-short-buffer

Conversation

@Aias00

@Aias00 Aias00 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Return false from Http2ProtocolProxyHandler.match() when fewer than 4 readable bytes are available.
  • Add regression coverage for empty/short buffers and the valid HTTP/2 PRI prefix.

Fixes #10776.

Verification

mvn -pl proxy -Dtest=Http2ProtocolProxyHandlerTest test

Result: BUILD SUCCESS. Http2ProtocolProxyHandlerTest ran 3 tests with 0 failures, errors, or skips. Checkstyle and SpotBugs also passed in the Maven run.

Copilot AI review requested due to automatic review settings August 3, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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() >= 4 guard before reading the HTTP/2 PRI prefix as an int.
  • Add unit tests covering empty buffers, short buffers (<4 bytes), and the valid PRI prefix.

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.

Comment on lines 50 to 54
@Before
public void setUp() throws Exception {
ConfigurationManager.initConfig();
ConfigurationManager.getProxyConfig().setEnableRemotingLocalProxyGrpc(true);
http2ProtocolProxyHandler = new Http2ProtocolProxyHandler();
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.22%. Comparing base (eddb235) to head (7d9f063).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() < 4 and returning null to signal "need more data" is the standard Netty pattern for protocol decoders.
  • [Info] Test coverage is good — testDecodeShortBufferReject verifies rejection of short buffers, and testDecodeHttp2PrefacePrefix verifies valid HTTP/2 preface detection still works.

Suggestions

  • None. Clean, minimal fix with proper test coverage.

LGTM.


Automated review by github-manager-bot

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.

[Bug] Http2ProtocolProxyHandler.match throws on short ByteBuf

4 participants