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/fury.git
The following commit(s) were added to refs/heads/main by this push:
new bda04fe7 fix(java): fix read null chunk out of bound (#2065)
bda04fe7 is described below
commit bda04fe7a5ff763f000b7c3db1ca0e3cdd6dc833
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Feb 17 23:58:28 2025 +0800
fix(java): fix read null chunk out of bound (#2065)
## What does this PR do?
fix read null chunk out of bound
## Related issues
Closes #2062
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fury/issues/new/choose) describing the
need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
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.
-->
---
.../fury/serializer/collection/AbstractMapSerializer.java | 2 +-
.../fury-core/src/test/java/org/apache/fury/StreamTest.java | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
index 274f36b7..d9741139 100644
---
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
+++
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java
@@ -679,7 +679,7 @@ public abstract class AbstractMapSerializer<T> extends
Serializer<T> {
} else {
readNullKeyChunk(buffer, map, chunkHeader, valueSerializer,
valueHasNull);
}
- if (size-- == 0) {
+ if (--size == 0) {
return 0;
} else {
chunkHeader = buffer.readUnsignedByte();
diff --git a/java/fury-core/src/test/java/org/apache/fury/StreamTest.java
b/java/fury-core/src/test/java/org/apache/fury/StreamTest.java
index 56e7da3c..51baa9db 100644
--- a/java/fury-core/src/test/java/org/apache/fury/StreamTest.java
+++ b/java/fury-core/src/test/java/org/apache/fury/StreamTest.java
@@ -34,6 +34,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.fury.config.CompatibleMode;
import org.apache.fury.io.FuryInputStream;
import org.apache.fury.io.FuryReadableChannel;
@@ -378,4 +379,16 @@ public class StreamTest extends FuryTestBase {
assertEquals(fury.deserialize(stream), new long[5000]);
assertEquals(fury.deserialize(stream), new int[5000]);
}
+
+ @Test
+ public void testReadNullChunkMapOnFillBound() {
+ Fury fury = builder().build();
+ Map<String, String> m = new HashMap<>();
+ m.put("1", null);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(100);
+ fury.serialize(outputStream, m);
+ InputStream inputStream = new
ByteArrayInputStream(outputStream.toByteArray());
+ FuryInputStream input = new FuryInputStream(inputStream);
+ assertEquals(fury.deserialize(input), m);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]