Skip to content

Guard ProcessPacket against short/malformed UDP packets - #4

Merged
otoyuzu705 merged 2 commits into
feat/art-netfrom
copilot/sub-pr-3
Mar 13, 2026
Merged

Guard ProcessPacket against short/malformed UDP packets#4
otoyuzu705 merged 2 commits into
feat/art-netfrom
copilot/sub-pr-3

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

ProcessPacket accessed fixed byte offsets 0–17 and called Buffer.BlockCopy from offset 18 without validating data.Length, causing IndexOutOfRangeException or ArgumentException on any short or malformed UDP packet.

Changes

  • Minimum header length checkif (data.Length < 18) return; added immediately after the null guard, before any index access
  • Payload bounds checkif (data.Length < 18 + length) return; added after extracting length, preventing BlockCopy from reading past the buffer end
  • Tightened length validationlength < 0 || length > 512 to be explicit about both bounds
if (data == null) return;
if (data.Length < 18) return;           // guards all fixed-offset reads (bytes 0–17)

// ... header/opcode validation ...

int length = (data[16] << 8) | data[17];
if (length < 0 || length > 512) return;
if (data.Length < 18 + length) return;  // guards BlockCopy

Buffer.BlockCopy(data, 18, dmxData, 0, length);

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…angeException

Co-authored-by: otoyuzu705 <107416827+otoyuzu705@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on Art-Net・DMX implementation and tutorial removal Guard ProcessPacket against short/malformed UDP packets Mar 13, 2026
Copilot AI requested a review from otoyuzu705 March 13, 2026 02:54
@otoyuzu705
otoyuzu705 marked this pull request as ready for review March 13, 2026 03:08
@otoyuzu705

Copy link
Copy Markdown
Owner

@copilot
コメントは日本語でして

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
コメントは日本語でして

了解しました。今後のコメントは日本語で記載します。なお、今回追加したコードコメントはすでに日本語で記載しています(例:// パケット長の最低限チェック(ヘッダー18バイト以上必要)// DMXデータ領域の長さチェック)。

@otoyuzu705 otoyuzu705 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@otoyuzu705
otoyuzu705 merged commit 2fe30eb into feat/art-net Mar 13, 2026
1 check passed
@otoyuzu705
otoyuzu705 deleted the copilot/sub-pr-3 branch March 13, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants