This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch releases-0.12
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/releases-0.12 by this push:
new 2e3dc3a43 fix(java): row format buffer recycling leaves offset and
size for null values (#2540)
2e3dc3a43 is described below
commit 2e3dc3a432dffe6e1715b8d26f7d10ebc14bbbb6
Author: Steven Schlansker <[email protected]>
AuthorDate: Thu Sep 4 20:29:56 2025 -0700
fix(java): row format buffer recycling leaves offset and size for null
values (#2540)
---
.../fory/format/row/binary/writer/BinaryRowWriter.java | 6 ++++++
.../fory/format/row/binary/writer/BinaryWriter.java | 6 +++---
.../org/apache/fory/format/encoder/RowEncoderTest.java | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git
a/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryRowWriter.java
b/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryRowWriter.java
index 9cbd48d05..c46538881 100644
---
a/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryRowWriter.java
+++
b/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryRowWriter.java
@@ -128,6 +128,12 @@ public class BinaryRowWriter extends BinaryWriter {
writeDecimal(ordinal, value, (ArrowType.Decimal)
schema.getFields().get(ordinal).getType());
}
+ @Override
+ public void setNullAt(int ordinal) {
+ super.setNullAt(ordinal);
+ write(ordinal, 0L);
+ }
+
public BinaryRow getRow() {
BinaryRow row = new BinaryRow(schema);
int size = size();
diff --git
a/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryWriter.java
b/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryWriter.java
index d24d547ed..8e08b054c 100644
---
a/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryWriter.java
+++
b/java/fory-format/src/main/java/org/apache/fory/format/row/binary/writer/BinaryWriter.java
@@ -121,10 +121,10 @@ public abstract class BinaryWriter {
}
/**
- * Since writer is used for one-pass writer, same field won't be writer
twice. There is no need to
- * put zero into the corresponding field when set null.
+ * Writer might recycle buffers, so implementations should clear data from a
previous not-null
+ * write when setting null to avoid information leaks.
*/
- public final void setNullAt(int ordinal) {
+ public void setNullAt(int ordinal) {
BitUtils.set(buffer, startIndex + bytesBeforeBitMap, ordinal);
}
diff --git
a/java/fory-format/src/test/java/org/apache/fory/format/encoder/RowEncoderTest.java
b/java/fory-format/src/test/java/org/apache/fory/format/encoder/RowEncoderTest.java
index 484296456..c80febb64 100644
---
a/java/fory-format/src/test/java/org/apache/fory/format/encoder/RowEncoderTest.java
+++
b/java/fory-format/src/test/java/org/apache/fory/format/encoder/RowEncoderTest.java
@@ -118,4 +118,21 @@ public class RowEncoderTest {
Assert.assertEquals(s1.f1, s.f1);
Assert.assertEquals(s1.f2, s.f2);
}
+
+ @Test
+ public void testNullClearOffset() {
+ RowEncoder<Bar> encoder = Encoders.bean(Bar.class);
+ Bar bar = new Bar();
+ bar.f1 = 42;
+ bar.f2 = null;
+ byte[] nullBefore = encoder.encode(bar);
+
+ bar.f2 = "not null";
+ // write offset and size
+ encoder.encode(bar);
+
+ bar.f2 = null;
+ byte[] nullAfter = encoder.encode(bar);
+ Assert.assertEquals(nullAfter, nullBefore);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]