Skip to content

Commit bda04fe

Browse files
authored
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. -->
1 parent 0fe042a commit bda04fe

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

java/fury-core/src/main/java/org/apache/fury/serializer/collection/AbstractMapSerializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public long readJavaNullChunk(
679679
} else {
680680
readNullKeyChunk(buffer, map, chunkHeader, valueSerializer, valueHasNull);
681681
}
682-
if (size-- == 0) {
682+
if (--size == 0) {
683683
return 0;
684684
} else {
685685
chunkHeader = buffer.readUnsignedByte();

java/fury-core/src/test/java/org/apache/fury/StreamTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.ArrayList;
3535
import java.util.HashMap;
3636
import java.util.List;
37+
import java.util.Map;
3738
import org.apache.fury.config.CompatibleMode;
3839
import org.apache.fury.io.FuryInputStream;
3940
import org.apache.fury.io.FuryReadableChannel;
@@ -378,4 +379,16 @@ public void testBigBufferStreamingMetaShared() throws IOException {
378379
assertEquals(fury.deserialize(stream), new long[5000]);
379380
assertEquals(fury.deserialize(stream), new int[5000]);
380381
}
382+
383+
@Test
384+
public void testReadNullChunkMapOnFillBound() {
385+
Fury fury = builder().build();
386+
Map<String, String> m = new HashMap<>();
387+
m.put("1", null);
388+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(100);
389+
fury.serialize(outputStream, m);
390+
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
391+
FuryInputStream input = new FuryInputStream(inputStream);
392+
assertEquals(fury.deserialize(input), m);
393+
}
381394
}

0 commit comments

Comments
 (0)