chaoyoung opened a new issue, #16580:
URL: https://github.com/apache/dubbo/issues/16580

   ### Pre-check
   
   - [x] I am sure that all the content I provide is in English.
   
   
   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dubbo/issues?q=is%3Aissue) and found no 
similar issues.
   
   
   ### Apache Dubbo Component
   
   Java SDK (apache/dubbo)
   
   ### Dubbo Version
   
   3.3.8-SNAPSHOT (3.3 branch at 1cf125c421691ab2b3f1b82f0125be03eff338c9); 
also reproduced with released 3.3.7. OpenJDK 25, macOS.
   
   ### Steps to reproduce this issue
   
   ### Pre-check
   
   - [x] The report is in English.
   - [x] Searched existing issues and pull requests; no matching runtime 
constructor failure found.
   
   ### Apache Dubbo Component
   
   Java SDK (apache/dubbo)
   
   ## Environment
   
   - Apache Dubbo `3.3` branch, commit 
`1cf125c421691ab2b3f1b82f0125be03eff338c9` (`3.3.8-SNAPSHOT`).
   - Upstream regression tests reproduced with OpenJDK 25 on macOS.
   - Separate released-version TCP checks used official Dubbo 3.3.6 and 3.3.7 
with Netty 4.2.19.Final and OpenJDK 25. A nonempty StringValue request / 
default BytesValue response works on 3.3.6; on 3.3.7 the provider executes but 
the unary caller receives null. An empty request fails before provider 
invocation. Following nonempty calls still work on the same connection. These 
TCP checks are separate from the upstream test counts below.
   
   ## Description
   
   An uncompressed Triple/gRPC frame with a zero-length message body is 
rejected by `LengthFieldStreamingDecoder` before the fragment listener can 
deserialize it. An empty protobuf wire payload is valid for messages whose 
fields have their default values, such as `StringValue.getDefaultInstance()` or 
`google.protobuf.Empty`.
   
   `GrpcStreamingDecoder` delegates uncompressed messages to 
`LengthFieldStreamingDecoder.readMessageStream`. Its `BoundedInputStream` 
passes the payload length directly to `BufferedInputStream` as the buffer size. 
For length zero, the JDK constructor throws `IllegalArgumentException: Buffer 
size <= 0`.
   
   ## Minimal reproduction
   
   This uses only public Dubbo APIs and the same one-byte flag/four-byte length 
layout as an uncompressed gRPC frame:
   
   ```java
   LengthFieldStreamingDecoder decoder = new LengthFieldStreamingDecoder(1, 4);
   decoder.setFragmentListener(new StreamingDecoder.FragmentListener() {
       @Override
       public void bytesRead(int numBytes) {}
   
       @Override
       public void onFragmentMessage(java.io.InputStream input, int length) {
           org.junit.jupiter.api.Assertions.assertEquals(0, length);
       }
   });
   decoder.request(1);
   decoder.decode(new java.io.ByteArrayInputStream(new byte[] {0, 0, 0, 0, 0}));
   ```
   
   Expected: deliver one fragment of length zero, with an empty input stream, 
and account for the five header bytes.
   
   Actual: throw before invoking `onFragmentMessage`:
   
   ```text
   java.lang.IllegalArgumentException: Buffer size <= 0
       at 
java.base/java.io.BufferedInputStream.<init>(BufferedInputStream.java:...)
       at 
org.apache.dubbo.remoting.http12.message.LengthFieldStreamingDecoder$BoundedInputStream.<init>(LengthFieldStreamingDecoder.java:...)
   ```
   
   ## Upstream regression test
   
   The proposed test-only change in 
`dubbo-remoting/dubbo-remoting-http12/src/test/java/org/apache/dubbo/remoting/http12/message/LengthFieldStreamingDecoderTest.java`
 reproduces this directly in Dubbo's Maven reactor, using its existing protobuf 
dependency. No separate application or POM is needed:
   
   ```sh
   mvn -B -pl dubbo-remoting/dubbo-remoting-http12 -am test \
     -Dtest=LengthFieldStreamingDecoderTest \
     -Dsurefire.failIfNoSpecifiedTests=false \
     -Dspotless.skip=true -Dcheckstyle.skip=true -Drat.skip=true
   ```
   
   With those tests added before the fix, all seven new invocations fail with 
`IllegalArgumentException: Buffer size <= 0`, while the two existing 
invocations pass. The regression tests use `StringValue.parseFrom` and cover 
adjacent empty/nonempty messages, one-message demand, and input split across 
each position of the empty frame header.
   
   AI assistance was used to prepare the reproduction and proposed fix.
   
   ### Related reports
   
   #16554 concerns zero-length read behavior at EOF in a different InputStream. 
#15629 and #16324 concern generated Java signatures for google.protobuf.Empty. 
Neither covers constructing a BufferedInputStream with buffer size zero for an 
otherwise valid wire payload.
   
   ### Willingness to contribute
   
   I plan to submit a focused fix and regression tests.
   
   
   ### What you expected to happen
   
   A valid zero-length protobuf payload should reach the fragment listener and 
deserialize to its default message instance. Instead, BufferedInputStream 
throws IllegalArgumentException: Buffer size <= 0 before listener invocation.
   
   ### Anything else
   
   Focused fix and regression tests: 
https://github.com/chaoyoung/dubbo/tree/codex/triple-empty-protobuf . Before 
fix: seven new test invocations fail; after fix: nine decoder test invocations 
pass. Full http12 package: 38 tests, no failures/errors, two existing 
Linux-only XML tests skipped on macOS. AI assistance was used to prepare the 
reproduction and proposed fix.
   
   ### Do you have a (mini) reproduction demo?
   
   - [x] Yes, I have a minimal reproduction demo to help resolve this issue 
more effectively!
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [x] Yes I am willing to submit a pull request on my own!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to