Skip to content

Commit

Permalink
fix: BufferOverflowException when import data fix #3728 (#3729)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwh authored Feb 22, 2024
1 parent 15de293 commit 1a714ee
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public boolean build() {
result.putInt(totalSize); // Size
result.put(nullBitmap.getBuffer()); // BitMap
result.put(baseFieldBuf.array()); // Base data type
result.put(strAddrBuf.array()); // String addr
result.put(strAddrBuf.array(), 0, strAddrLen); // String addr
result.put(stringWriter.toByteArray()); // String value
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,5 +1018,41 @@ public void testSpecialCase() {
Assert.fail();
}
}

@Test
public void testLongString() {
try {
List<ColumnDesc> schema = new ArrayList<ColumnDesc>();
schema.add(ColumnDesc.newBuilder().setName("col1").setDataType(DataType.kInt).build());
schema.add(ColumnDesc.newBuilder().setName("col2").setDataType(DataType.kString).build());
schema.add(ColumnDesc.newBuilder().setName("col3").setDataType(DataType.kInt).build());
schema.add(ColumnDesc.newBuilder().setName("col4").setDataType(DataType.kString).build());
schema.add(ColumnDesc.newBuilder().setName("col5").setDataType(DataType.kString).build());
RowBuilder builder = new FlexibleRowBuilder(schema);
for (int i = 0; i < 20; i++) {
String str1 = genRandomString(100);
String str2 = i % 2 == 0 ? genRandomString(255) : genRandomString(20);
String str3 = i % 2 == 0 ? genRandomString(1000) : genRandomString(10);
Assert.assertTrue(builder.appendInt(1));
Assert.assertTrue(builder.appendString(str1));
Assert.assertTrue(builder.appendInt(10));
Assert.assertTrue(builder.appendString(str2));
Assert.assertTrue(builder.appendString(str3));
builder.build();

ByteBuffer buffer = builder.getValue();
RowView rowView = new RowView(schema, buffer, buffer.capacity());
Assert.assertEquals(rowView.getInt(0), new Integer(1));
Assert.assertEquals(rowView.getString(1), str1);
Assert.assertEquals(rowView.getString(3), str2);
Assert.assertEquals(rowView.getString(4), str3);

((FlexibleRowBuilder)builder).clear();
}
} catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
}

0 comments on commit 1a714ee

Please sign in to comment.