Out-of-bounds write in HLSLTokenizer::Next() when a preset shader identifier exceeds 255 characters

オープン 初心者向け
#1,053 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cmake, cpp
領域
backend, security

調査の方向性

識別子のスキャン付近にある vendor/hlslparser/src/HLSLTokenizer.cpp と、識別子バッファのサイズが分かる vendor/hlslparser/src/HLSLTokenizer.h を読み、ScanLineDirective() の範囲を制限したスキャンと比較してください。報告された AddressSanitizer ハーネスを使い、255 文字を超える識別子で再現してから、修正によって安全に処理され、エラーが報告されることを確認してください。オーバーフローがなくなり、通常の tokenizer の動作が維持されれば完了です。

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

説明

bug triage
Please confirm the following points:
  • This report is NOT about the Android apps in the Play Store
  • I have searched the project page to check if the issue was already reported
Affected Project

libprojectM (including the playlist library)

Affected Version

4.1.8 (Git tag v4.1.8)

Operating Systems and Architectures

All

Build Tools

Build Tool: CMake

Additional Project, OS and Toolset Details

Bug is in vendor/hlslparser/src/HLSLTokenizer.cpp (identifier scan) and is
independent of OS, architecture, compiler and build system. Reproduced with
clang++ -fsanitize=address against the vendored tokenizer compiled in isolation.
Reachable in normal use via MilkdropShader::TranspileHLSLShader() when a preset's
warp/composite shader is parsed.

Type of Defect

Build failure (compiler/linker or toolset error)

Log Output
==12345==ERROR: AddressSanitizer: stack-buffer-overflow
WRITE of size 5000 at 0x... thread T0
    #0 memcpy
    #1 M4::HLSLTokenizer::Next(bool)          HLSLTokenizer.cpp:289
    #2 M4::HLSLTokenizer::HLSLTokenizer(...)   HLSLTokenizer.cpp:166
    #3 main                                    harness.cpp
  [128, 696) 'tok' <== Memory access at offset 696 overflows this variable
Describe the Issue
Summary

M4::HLSLTokenizer::Next() copies an identifier token into the fixed 256-byte
member m_identifier using memcpy with a length taken directly from the input,
with no bounds check. A Milkdrop preset whose warp/composite shader contains an
identifier longer than 255 characters triggers an out-of-bounds write.

Location

vendor/hlslparser/src/HLSLTokenizer.cpp, identifier scan:

size_t length = m_buffer - start;      // unbounded
memcpy(m_identifier, start, length);   // OOB write when length > 255
m_identifier[length] = 0;              // OOB terminator too

m_identifier is char[s_maxIdentifier] with s_maxIdentifier = 256
(HLSLTokenizer.h). length is never compared against it. The #line parser
ScanLineDirective() in the same file shows the correct bounded loop that this
path is missing.

Reachability

MilkdropPreset load → MilkdropShader::TranspileHLSLShader()
(src/libprojectM/MilkdropPreset/MilkdropShader.cpp) → HLSLParser::Parse()
→ HLSLTokenizer. The tokenizer starts scanning in its constructor, so the
overflow fires during lexing — no valid-shader semantics required.

Proof of concept

A tokenizer constructed over a buffer containing one 5000-char identifier
(e.g. 5000 'A's) overflows under AddressSanitizer; see log output above.
End-to-end, a .milk preset with a 256+ char identifier token in warp_1/comp_1
reaches the same path.

Impact

Out-of-bounds write of attacker-controlled length and content from an untrusted
preset file. Minimum demonstrated impact is a reliable crash (DoS); code
execution cannot be excluded given the write primitive.

Suggested fix

Clamp the length to the buffer size before copying (patch attached):

size_t length = m_buffer - start;
if (length > s_maxIdentifier - 1) { length = s_maxIdentifier - 1; Error("Identifier too long"); }
memcpy(m_identifier, start, length);
m_identifier[length] = 0;

More Detils.zip

主要言語
C++
スター
4.6k
フォーク
498
平均マージ
19日 3時間
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

projectM-visualizer/projectm のほかの issue

projectM-visualizer/projectm の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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