Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

BUG: ManyShotJailbreakAttack accepts a negative example_count and drops examples from the end

オープン
#3,393 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

2026年10月20日 から。

  • #3395 @ShivamSharma43 による — オープン

評価

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

調査の方向性

Start at ManyShotJailbreakAttack.validate_constructor_parameters and the construction path described in the issue; check how the REST TechniqueService.create_async path uses that validation. Add coverage for non-positive, boolean, and non-integer example_count values at construction and validation, then confirm invalid values raise a ValueError naming example_count. An open linked pull request (#3395) indicates work is already underway.

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

説明

Describe the bug

ManyShotJailbreakAttack uses example_count as a slice bound (examples[:example_count]), but validate_constructor_parameters only rejects 0. A negative count is accepted and silently drops examples from the end of the list instead of selecting from the start, so example_count=-1 with the bundled dataset sends 399 examples, and with five custom examples -1 keeps four and -4 keeps one. True is accepted as 1, and non-integers fail with an unrelated error (2.5 raises TypeError: slice indices must be integers..., -5 with five examples raises the misleading Many shot examples must be provided.).

Because the check sits in validate_constructor_parameters, the REST technique API (TechniqueService.create_async) also accepts {"example_count": -1} and stores a technique that later runs with the wrong number of examples. The neighbouring bounds in that API (max_attempts_on_failure, max_turns, tree_depth, chunk_size, ...) are all rejected up front.

Steps/Code to Reproduce
import asyncio
from unittest.mock import MagicMock

from pyrit.executor.attack import ManyShotJailbreakAttack
from pyrit.prompt_target import PromptTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit_async

asyncio.run(initialize_pyrit_async(memory_db_type=IN_MEMORY))

target = MagicMock(spec=PromptTarget)
examples = [{"user": f"q{i}", "assistant": f"a{i}"} for i in range(5)]

for count in (-1, -4, True):
    attack = ManyShotJailbreakAttack(objective_target=target, example_count=count, many_shot_examples=examples)
    print(count, len(attack._examples))

print(len(ManyShotJailbreakAttack(objective_target=target, example_count=-1)._examples))
Expected Results

example_count values that are not positive integers raise a ValueError naming example_count, both at construction and in validate_constructor_parameters.

Actual Results
-1 4
-4 1
True 1
399
Screenshots

N/A

Versions
  • OS: Windows 11
  • Python version: 3.11.9
  • PyRIT version: installed from main (1979257a) in editable mode
主要言語
Python
スター
4.6k
フォーク
962
平均マージ
2日 15時間
マージ済み PR(30日)
398

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

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

microsoft/PyRIT のほかの issue

microsoft/PyRIT の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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