
src/decoders/pana8.cpp に範囲外配列読み取りが存在します。関数 GetDBit() は、ハフマンテーブルに一致するものが見つからない場合に値 17 を返す可能性がありますが、huff_coeff[] は 17 個の要素(有効なインデックス 0~16)で宣言されています。その結果、huff_coeff[17] にアクセスし、UBSan および AddressSanitizer によって確認された未定義動作を引き起こします。
ユーザーから提供された RW2 ファイルを処理するアプリケーション(画像エディタや LibRaw を使用する写真管理ツールなど)は、悪意のあるファイルを開くことでクラッシュしたり、プロセスメモリがリークする可能性があります。
CWE: CWE-125(範囲外読み取り)、CWE-129(配列インデックスの不適切な検証) CVSS v3.1: AV:L/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:H (~6.5 Medium)
Git commit: 777f20ae21c611a78021bd051fbbf1e71eae78f2
ファイル: src/decoders/pana8.cpp 関数: pana8_param_t::DecodeC8()
根本原因は GetDBit() にあります。
uint32_t pana8_param_t::GetDBit(uint64_t a2)
{
for (int i = 0; i < 16; i++)
if ((a2 & hufftable2[i]) == hufftable1[i])
return i;
return uint32_t((hufftable2[16] & a2) == hufftable1[16]) ^ 0x11u;
// 比較が偽の場合: 0 ^ 17 = 17 を返す
}
戻り値は範囲チェックなしで直接配列インデックスとして使用されます。
huff_index = int(GetDBit(pixbits)); // 17 になる可能性あり
int32_t v37 = (huff_coeff[huff_index] >> 24) // 250行目: 範囲外
uint32_t hc = huff_coeff[huff_index]; // 251行目: 範囲外
// ... 254行目、273行目
確認された呼び出しチェーン(UBSan 出力) LibRaw::unpack() -> panasonicC8_load_raw() pana8.cpp:125 -> pana8_decode_loop() pana8.cpp:132 -> pana8_decode_strip() pana8.cpp:155 -> DecodeC8() pana8.cpp:250 <-- 範囲外トリガー
UBSan エラーが発生しました: pana8.cpp:250 index 17 out of bounds for type 'unsigned int [17]' pana8.cpp:251 index 17 out of bounds for type 'unsigned int [17]' pana8.cpp:254 index 17 out of bounds for type 'unsigned int [17]' pana8.cpp:254 shift exponent -17 is negative pana8.cpp:273 index 17 out of bounds for type 'unsigned int [17]' pana8.cpp:303 left shift of negative value -1
サニタイザ付きで LibRaw をビルドします。
./configure CXXFLAGS="-fsanitize=address,undefined -g -O1" \
LDFLAGS="-fsanitize=address,undefined"
make -j$(nproc)
任意の Panasonic RW2 ファイルに対して mutator スクリプトを実行します。
python3 mutate_rw2.py input.rw2 mutated_pana8.rw2
ASAN_OPTIONS=halt_on_error=0:print_stats=1 ./bin/dcraw_emu -v mutated_pana8.rw2
https://github.com/LibRaw/LibRaw/commit/02da167e0f819a37dbb7d714e87c5b40df6c5917