Byte-array elements leak in `FromSchemaByteArray()`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
Direzione di ricerca
Inizia in dataset/src/main/cpp/jni_util.cc, in FromSchemaByteArray(), e ispeziona il flusso di GetByteArrayElements, ReadSchema e ReleaseByteArrayElements. Verifica che il rilascio avvenga anche quando l’analisi non riesce, quindi esegui il percorso di uno schema malformato o incompatibile tramite createDataset(); il lavoro è completato quando gli elementi dell’array JNI acquisiti vengono rilasciati sia nei percorsi di successo sia in quelli di errore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug, including details regarding any error messages, version, and platform.
I found a possible JNI array leak in FromSchemaByteArray() when the serialized schema cannot be parsed.
File: dataset/src/main/cpp/jni_util.cc
Function: FromSchemaByteArray
Relevant code:
jbyte* schemaBytes_data =
env->GetByteArrayElements(schemaBytes, nullptr);
auto serialized_schema = std::make_shared<arrow::Buffer>(
reinterpret_cast<uint8_t*>(schemaBytes_data),
schemaBytes_len);
arrow::io::BufferReader buf_reader(serialized_schema);
ARROW_ASSIGN_OR_RAISE(
std::shared_ptr<arrow::Schema> schema,
arrow::ipc::ReadSchema(&buf_reader, &in_memo))
env->ReleaseByteArrayElements(
schemaBytes, schemaBytes_data, JNI_ABORT);
return schema;
GetByteArrayElements() returns a pointer that must be paired with
ReleaseByteArrayElements().
ARROW_ASSIGN_OR_RAISE returns immediately when ReadSchema() returns an
error. On that path, the release below the macro is skipped, so the acquired
array elements remain unreleased:
GetByteArrayElements succeeds
-> ReadSchema returns an error
-> ARROW_ASSIGN_OR_RAISE returns
-> ReleaseByteArrayElements is skipped
The function is used by the public native createDataset() method:
schema = JniGetOrThrow(
FromSchemaByteArray(env, schema_bytes));
Malformed, corrupted, or incompatible serialized schema bytes can therefore
reach this path. Repeated failed calls can retain copied array buffers or keep
Java arrays pinned, depending on the JVM implementation.
Suggested fix: release the elements before propagating the parse result, for
example:
auto schema_result =
arrow::ipc::ReadSchema(&buf_reader, &in_memo);
env->ReleaseByteArrayElements(
schemaBytes, schemaBytes_data, JNI_ABORT);
return schema_result;
An RAII guard for schemaBytes_data would also ensure release if additional
early returns are introduced later.
- Lingua principale
- Java
- Stelle
- 95
- Fork
- 154
- Merge medio
- 2g 16h
- PR unite (30g)
- 9
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/arrow-java
-
Type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/arrow-java#1300 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
apache/arrow-java#1261 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/arrow-java#1236 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/arrow-java#1230 ·
-
Type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
apache/arrow-java#1196 · 1 commento ·
Tutte le issue di apache/arrow-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100