DecimalVector.setBigEndian writes oversized value before validating length
- Lingua principale
- Java
- Stelle
- 94
- Fork
- 152
- Merge medio
- 3g 16h
- PR unite (30g)
- 11
Descrizione
DecimalVector.setBigEndian(int, byte[]) and Decimal256Vector.setBigEndian(int, byte[]) validate the input length only after copying the bytes. On a little-endian platform the method byte-swaps the value into the fixed 16/32-byte slot with a loop of unchecked MemoryUtil.putByte writes:
```java
for (int byteIdx = 0; byteIdx < length; ++byteIdx) {
MemoryUtil.putByte(outAddress + byteIdx, value[length - 1 - byteIdx]);
}
...
throw new IllegalArgumentException("Invalid decimal value length. Valid length in [1 - 16], got " + length);
```
If value.length exceeds the type width, the loop writes past the slot into adjacent off-heap memory before the IllegalArgumentException is thrown. MemoryUtil.putByte does no bounds checking, so this corrupts memory in the default configuration. setBigEndianSafe(int, long, ArrowBuf, int) performs the same write with no length check at all.
Reproducer: write a value into slot 1, then call setBigEndian(0, new byte[24]) on a DecimalVector; slot 1 is left corrupted (the write spills 8 bytes into it) even though the call throws.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia da DecimalVector.setBigEndian e Decimal256Vector.setBigEndian, quindi confronta setBigEndianSafe; esamina come vengono gestiti gli slot a larghezza fissa e la validazione della lunghezza. Riproduci un input sovradimensionato per uno slot diverso da zero e aggiungi una copertura che dimostri che la memoria adiacente rimane invariata, mentre le lunghezze non valide continuano a generare un'eccezione. Il lavoro è completato quando tutti e tre i punti di ingresso rifiutano i valori sovradimensionati prima della scrittura.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- data
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 72/100