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

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 6c6ba3fb4 fix(java): fix unbounded LinkedBlockingQueue deserialization 
(#3786)
6c6ba3fb4 is described below

commit 6c6ba3fb4172a71811c57664ae2a892f04208b5b
Author: 0sense <[email protected]>
AuthorDate: Thu Jun 25 03:53:36 2026 +0200

    fix(java): fix unbounded LinkedBlockingQueue deserialization (#3786)
    
    ## Why?
    
    `LinkedBlockingQueueSerializer` fails to deserialize default unbounded
    `new LinkedBlockingQueue<>()`. Serialize works, deserialize throws
    `IndexOutOfBoundsException` because capacity on the wire is
    `Integer.MAX_VALUE` and `checkReadableBytes(capacity)` tries to read
    ~2GB. Bounded queues like `new LinkedBlockingQueue<>(16)` work fine.
    
    ## What does this PR do?
    
    - Drop `checkReadableBytes(capacity)` in
    `LinkedBlockingQueueSerializer.newCollection`
    - Add regression test for unbounded queue round-trip
    
    ## Related issues
    
    - Fixes #3783
    
    ## AI Contribution Checklist
    
    - [x] Substantial AI assistance was used in this PR: `no`
    
    ---------
    
    Co-authored-by: Shawn Yang <[email protected]>
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
---
 .../apache/fory/serializer/collection/CollectionSerializers.java  | 1 -
 .../fory/serializer/collection/CollectionSerializersTest.java     | 8 ++++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializers.java
 
b/java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializers.java
index 7c67d1607..a81c38298 100644
--- 
a/java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializers.java
+++ 
b/java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializers.java
@@ -994,7 +994,6 @@ public class CollectionSerializers {
       setNumElements(numElements);
       int capacity = buffer.readVarUInt32Small7();
       checkBoundedQueueCapacity(numElements, capacity);
-      buffer.checkReadableBytes(capacity);
       LinkedBlockingQueue queue = new LinkedBlockingQueue<>(capacity);
       readContext.reference(queue);
       return queue;
diff --git 
a/java/fory-core/src/test/java/org/apache/fory/serializer/collection/CollectionSerializersTest.java
 
b/java/fory-core/src/test/java/org/apache/fory/serializer/collection/CollectionSerializersTest.java
index c4d5a3573..ebff4537e 100644
--- 
a/java/fory-core/src/test/java/org/apache/fory/serializer/collection/CollectionSerializersTest.java
+++ 
b/java/fory-core/src/test/java/org/apache/fory/serializer/collection/CollectionSerializersTest.java
@@ -1153,6 +1153,14 @@ public class CollectionSerializersTest extends 
ForyTestBase {
       assertEquals(new ArrayList<>(deserialized), new ArrayList<>(queue));
       assertEquals(deserialized.remainingCapacity() + deserialized.size(), 3);
     }
+    {
+      LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
+      queue.add(1);
+      queue.add(2);
+      LinkedBlockingQueue<Integer> deserialized = serDe(fory, queue);
+      assertEquals(new ArrayList<>(deserialized), new ArrayList<>(queue));
+      assertEquals(deserialized.remainingCapacity() + deserialized.size(), 
Integer.MAX_VALUE);
+    }
   }
 
   @Test


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

Reply via email to