Skip to content

Commit

Permalink
Add warning comments for memory safety risk
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Jan 10, 2024
1 parent 5a39c62 commit 7a4bb1e
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ArrowToTableConverter {

private volatile boolean completed = false;

private BarrageProtoUtil.MessageInfo parseArrowIpcMessage(final ByteBuffer bb) throws IOException {
private static BarrageProtoUtil.MessageInfo parseArrowIpcMessage(final ByteBuffer bb) throws IOException {
final BarrageProtoUtil.MessageInfo mi = new BarrageProtoUtil.MessageInfo();

bb.order(ByteOrder.LITTLE_ENDIAN);
Expand All @@ -68,6 +68,11 @@ private BarrageProtoUtil.MessageInfo parseArrowIpcMessage(final ByteBuffer bb) t
return mi;
}

/**
* The input ByteBuffer instance (especially originated from Python) can't be assumed to be valid after the return
* of this method. Until jpy-consortium/jpy#126 is resolved, we need to copy the input ByteBuffer to a new
* ByteBuffer instance that is safe to use after the return of this method.
*/
@ScriptApi
public synchronized void setSchema(final ByteBuffer ipcMessage) {
if (completed) {
Expand All @@ -80,13 +85,23 @@ public synchronized void setSchema(final ByteBuffer ipcMessage) {
parseSchema((Schema) mi.header.header(new Schema()));
}

/**
* The input ByteBuffer instance (especially originated from Python) can't be assumed to be valid after the return
* of this method. Until jpy-consortium/jpy#126 is resolved, we need to copy the input ByteBuffer to a new
* ByteBuffer instance that is safe to use after the return of this method.
*/
@ScriptApi
public synchronized void addRecordBatches(final ByteBuffer... ipcMessages) {
for (final ByteBuffer ipcMessage : ipcMessages) {
addRecordBatch(ipcMessage);
}
}

/**
* The input ByteBuffer instance (especially originated from Python) can't be assumed to be valid after the return
* of this method. Until jpy-consortium/jpy#126 is resolved, we need to copy the input ByteBuffer to a new
* ByteBuffer instance that is safe to use after the return of this method.
*/
@ScriptApi
public synchronized void addRecordBatch(final ByteBuffer ipcMessage) {
if (completed) {
Expand Down

0 comments on commit 7a4bb1e

Please sign in to comment.