apache / apache/arrow-java

DecimalVector.setBigEndian writes oversized value before validating length

オープン
#1,246 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
94
フォーク
152
平均マージ
3日 16時間
マージ済み PR(30日)
11

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

DecimalVector.setBigEndian と Decimal256Vector.setBigEndian から始め、次に setBigEndianSafe と比較してください。固定幅スロットと長さの検証がどのように処理されているかを調べてください。ゼロではないスロットに対するサイズ超過の入力を再現し、無効な長さが引き続き例外をスローする一方で、隣接するメモリが変更されないことを示すテストカバレッジを追加してください。3つのエントリポイントすべてが書き込み前にサイズ超過の値を拒否すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
data
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
72/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。