BUG TokenBijectionConverter cannot represent a literal hyphen, so "e-mail" encodes identically to "email" and decodes without the hyphen
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start with pyrit/converter/bijection_converter.py and inspect TokenBijectionConverter's encoding, decoding pattern, and teaching instructions. Run the reproduction with the provided mapping, then check the converter tests under tests/unit/converter. Done means literal hyphens round-trip and e-mail encodes differently from email; the issue author says they already have a fix and regression tests ready to submit.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
TokenBijectionConverter (pyrit/converter/bijection_converter.py) joins the code words of one plaintext word with - (_TOKEN_DELIMITER), and encode() passes every unmapped character through unchanged. A hyphen in the plaintext is therefore emitted as the same character as the delimiter, and lands between two code-word runs exactly where an inserted delimiter would. decode()'s pattern (\b(tok)(?:-(tok))*\b) consumes it as a delimiter, so the hyphen disappears:
| plaintext | encoded (mapping x -> xxx) |
decoded |
|---|---|---|
email |
eee-mmm-aaa-iii-lll |
email |
e-mail |
eee-mmm-aaa-iii-lll |
email |
self-harm |
sss-eee-lll-fff-hhh-aaa-rrr-mmm |
selfharm |
The class docstring says the delimiter is there "to keep them legible and unambiguously decodable", and the teaching instructions tell the target to "join adjacent code words with hyphens", which leaves the model no way to write a literal hyphen either. So the prompt sent to the target loses hyphens on the way in ("self-harm" becomes "selfharm" once decoded), and any hyphen in the target's answer is lost on the way back.
This is the same collision class that has already been fixed twice in this file: #2696 (literal apostrophes vs. _CASE_MARKER) and #2741 (literal digits vs. digit tokens) in DigitBijectionConverter. The hyphen case in TokenBijectionConverter was not covered.
Steps/Code to Reproduce
import string
from pyrit.converter import TokenBijectionConverter
mapping = {c: c * 3 for c in string.ascii_lowercase} # explicit mapping, no tokenizer needed
conv = TokenBijectionConverter(tokenizer=None, mapping=mapping)
for text in ("e-mail", "email", "self-harm"):
enc = conv.encode(prompt=text)
print(text, "->", enc, "->", conv.decode(enc))
Expected Results
Each input round-trips, and e-mail does not encode to the same text as email.
e-mail -> eee--mmm-aaa-iii-lll -> e-mail
email -> eee-mmm-aaa-iii-lll -> email
self-harm -> sss-eee-lll-fff--hhh-aaa-rrr-mmm -> self-harm
Actual Results
e-mail -> eee-mmm-aaa-iii-lll -> email
email -> eee-mmm-aaa-iii-lll -> email
self-harm -> sss-eee-lll-fff-hhh-aaa-rrr-mmm -> selfharm
Hyphens that are not directly between two letters (a - b, -lead, trail-) happen to survive because the decode pattern requires a code word on both sides, so the loss is specific to hyphenated words, which is the common case.
Suggested fix
Escape a literal hyphen as a doubled delimiter (--) on encode, the same way DigitBijectionConverter doubles a literal apostrophe or tilde, and have the decode pattern match -- first and restore it to one hyphen. A doubled delimiter can never be produced by joining code words, so it is unambiguous. The teaching instructions should tell the target to write a literal hyphen as two hyphens.
I have the fix with regression tests ready and can open the PR. The new round-trip cases fail on main (6 failed) and pass with the change; tests/unit/converter passes in full.
Versions
- OS: macOS 26.5
- Python version: 3.14.8
- PyRIT version: 1.2.0.dev0, installed from
main(0a5abbf9) in editable mode
- Ngôn ngữ chính
- Python
- Star
- 4.6k
- Fork
- 944
- Merge trung bình
- 2 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 309
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/PyRIT
-
BUG UnicodeReplacementConverter writes characters outside the BMP as invalid five-digit \u escapesCó thể đã có người làm @ShivamSharma43 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG: label queries only return the final conversation of an attackCó thể đã có người làm @richlundeen đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microsoft/PyRIT#3095 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG Configuration keeps runtime-status errors after polling recoversCó thể đã có người làm @joeyvictorino đã nhận 2 ngày trước. Đang mởBug: triage GUI help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
microsoft/PyRIT#2868 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG JailBreakV-28K loader reads a `transfer_attack_type` column that does not exist upstream and drops the real `from` / `transfer_from_llm` provenanceCó thể đã có người làm @kushaltalati đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 35/100
microsoft/PyRIT#3161 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG QuestionAnswerScorer counts a wrong option as correct when the answer appears inside a longer word or numberCó thể đã có người làm @barkha1research-ai đã nhận hôm nay. Đang mởBug: triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/PyRIT
Issue tương tự
-
area: agents area: docs good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
openapi/gknowledge#23 ·
-
get() for StrEnumCó thể đã có người làm @FeJo5952 đã nhận hôm nay. Đang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
collective/icalendar#1921 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Improvement Python Spans
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-python#7994 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
alphagov/notifications-api#5004 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
equinor/radix-flux#3922 ·
Maintainer thường phản hồi trong vòng 1 ngày