USB PD: Structured VDM Command accepts values wider than the 5-bit field

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

@RobertZ2011 がすでに取り組んでいます。

2026年10月27日 から。

評価

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

調査の方向性

src/vdm/structured/header.rsを読み、特に42行目付近のCommand::try_from(u8)のmatchと、149~166行目付近のsvid_specific_upper_rangeテストを確認してください。テストを実行して受け入れられる値と拒否される値を確認し、31を超える値は拒否され、16~31は引き続き受け入れられるようにしてください。対象のテストが成功すれば完了です。

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

説明

BREAKING CHANGE bug conformance

Summary

Command::try_from(u8) accepts every value >= 16, including 127 and 255, although the wire field is five bits wide.

What the specification requires

USB PD R3.2 V1.2 S6.4.12.2, Table 6.33 (Structured VDM Header), Command is bits 4...0:

16...31 - SVID Specific Commands

Only 16 SVID-specific command codes exist.

What the code does

src/vdm/structured/header.rs#L42:

cmd if cmd >= 16 => Ok(Self::SvidSpecific(cmd)),

Command therefore has 262 inhabitants (6 named variants plus 256 payloads) for 22 defined command codes. The real wire decoder masks to five bits, so these values cannot arrive through that path, but the public enum and its conversion accept encodings that do not exist.

Failing test

svid_specific_upper_range on branch audit. The test previously asserted that 127 and 255 are accepted:

/// USB PD R3.2 V1.2 Table 6.33 (Structured VDM Header) defines Command as a
/// 5-bit field (bits 4...0), with "16...31 - SVID Specific Commands".
///
/// 127 and 255 are not encodable in a 5-bit field and must be rejected.
#[test]
fn svid_specific_upper_range() {
    for v in [16u8, 17, 31] {
        assert_eq!(Command::try_from(v), Ok(Command::SvidSpecific(v)));
    }
    for v in [32u8, 127, 255] {
        assert!(
            Command::try_from(v).is_err(),
            "raw={v} exceeds the 5-bit Command field (USB PD R3.2 V1.2 Table 6.33) \
             and should be rejected"
        );
    }
}

Suggested fix

Reject values above 31. Bounding the SvidSpecific payload so it cannot hold an unencodable value is breaking but removes the possibility entirely.

主要言語
Rust
スター
2
フォーク
8
平均マージ
1日 10時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

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

OpenDevicePartnership/embedded-usb-pd のほかの issue

OpenDevicePartnership/embedded-usb-pd の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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