This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch releases-0.10
in repository https://gitbox.apache.org/repos/asf/fury.git

commit 7c790e1b978badb3b912e05e9fc6ab3f5e585eec
Author: Zhanghao Chen <[email protected]>
AuthorDate: Tue May 6 17:11:14 2025 +0800

    fix(java): ensure FuryObjectInputStream.read never returns 0 when length>0 
#2204 (#2205)
    
    <!--
    **Thanks for contributing to Fury.**
    
    **If this is your first time opening a PR on fury, you can refer to
    
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).**
    
    Contribution Checklist
    
    - The **Apache Fury (incubating)** community has restrictions on the
    naming of pr titles. You can also find instructions in
    [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).
    
    - Fury has a strong focus on performance. If the PR you submit will have
    an impact on performance, please benchmark it first and provide the
    benchmark result here.
    -->
    
    ## What does this PR do?
    
    <!-- Describe the purpose of this PR. -->
    
    Ensure FuryObjectInputStream.read never returns 0 when length>0, so that
    when outer logic attempts to read in a while loop, it won't get stuck or
    throw exception.
    
    ## Related Issues
    #2204
    
    ## Does this PR introduce any user-facing change?
    
    No.
    
    ## Benchmark
    
    No measurable performance impact is expected.
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    -->
---
 .../main/java/org/apache/fury/serializer/ObjectStreamSerializer.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectStreamSerializer.java
 
b/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectStreamSerializer.java
index f3bf8f9f..dd4474a7 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectStreamSerializer.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/serializer/ObjectStreamSerializer.java
@@ -894,7 +894,8 @@ public class ObjectStreamSerializer extends 
AbstractObjectSerializer {
         throw new IndexOutOfBoundsException();
       }
       int remaining = buffer.remaining();
-      if (remaining < length) {
+      // When remaining = 0, also force to refill buffer to avoid getting stuck
+      if (remaining > 0 && remaining < length) {
         buffer.readBytes(buf, offset, remaining);
         return remaining;
       } else {


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

Reply via email to