@@ -275,21 +275,9 @@ public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers
275275 @ Override
276276 public List <ArrowBuf > getFieldBuffers () {
277277 List <ArrowBuf > result = new ArrayList <>(2 );
278-
279- // Ensure offset buffer has at least one entry for offset[0].
280- // According to Arrow specification, offset buffer must have N+1 entries,
281- // even when N=0, it should contain [0].
282- if (offsetBuffer .capacity () == 0 ) {
283- // Save and restore offsetAllocationSizeInBytes to avoid affecting subsequent allocateNew()
284- long savedOffsetAllocationSize = offsetAllocationSizeInBytes ;
285- offsetBuffer = allocateOffsetBuffer (OFFSET_WIDTH );
286- offsetAllocationSizeInBytes = savedOffsetAllocationSize ;
287- }
288-
289278 setReaderAndWriterIndex ();
290279 result .add (validityBuffer );
291280 result .add (offsetBuffer );
292-
293281 return result ;
294282 }
295283
@@ -318,14 +306,12 @@ public void exportCDataBuffers(List<ArrowBuf> buffers, ArrowBuf buffersPtr, long
318306 private void setReaderAndWriterIndex () {
319307 validityBuffer .readerIndex (0 );
320308 offsetBuffer .readerIndex (0 );
321- if (valueCount == 0 ) {
322- validityBuffer .writerIndex (0 );
323- // Even when valueCount is 0, offset buffer should have offset[0] per Arrow spec
324- offsetBuffer .writerIndex (Math .min (OFFSET_WIDTH , offsetBuffer .capacity ()));
325- } else {
326- validityBuffer .writerIndex (BitVectorHelper .getValidityBufferSizeFromCount (valueCount ));
327- offsetBuffer .writerIndex ((valueCount + 1 ) * OFFSET_WIDTH );
328- }
309+ validityBuffer .writerIndex (BitVectorHelper .getValidityBufferSizeFromCount (valueCount ));
310+ // IPC serializer will determine readable bytes based on `readerIndex` and `writerIndex`.
311+ // Both are set to 0 means 0 bytes are written to the IPC stream which will crash IPC readers
312+ // in other libraries. According to Arrow spec, we should still output the offset buffer which
313+ // is [0].
314+ offsetBuffer .writerIndex ((long ) (valueCount + 1 ) * OFFSET_WIDTH );
329315 }
330316
331317 /**
0 commit comments