BUG: PlagiarismScorer accepts invalid n-gram size and blank reference text
Maintainer thường phản hồi trong vòng 2 ngày
Một pull request liên quan đã được merge.
- #2972 của @RohithPariki — đã merge
Đá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
- 85/100
Hướng nghiên cứu
Bắt đầu trong pyrit/score/float_scale/plagiarism_scorer.py tại PlagiarismScorer.init, sau đó so sánh cách xử lý tham số của nó với phần validation của ApproximateTextMatching được mô tả trong issue. Chạy các test PlagiarismScorer hiện có và bổ sung coverage cho n không hợp lệ, văn bản tham chiếu trống và các metric không hợp lệ; hoàn thành khi quá trình khởi tạo từ chối từng trường hợp được liệt kê mà không thay đổi việc scoring hợp lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
PlagiarismScorer does not validate its n (n-gram size) or reference_text parameters during initialization.
-
n <= 0creates false-positive 100% plagiarism matches:
Whenn = 0,_ngram_setreturns{()}(an empty tuple). InPlagiarismMetric.JACCARD,len(ref_ngrams & res_ngrams) / len(ref_ngrams)evaluates to1 / 1 = 1.0for any response. A completely unrelated prompt response is therefore reported as 100% plagiarized.
Whenn < 0(e.g.n = -1), negative slicing produces spurious n-grams and invalid partial overlap scores (e.g.0.5).
Whennis a non-integer float (e.g.2.5), construction succeeds, but scoring later crashes withTypeError: 'float' object cannot be interpreted as an integer.
Whennis a boolean (e.g.False), it evaluates as0and yields the same false-positive1.0. -
Empty or whitespace-only
reference_textsilently reports0.0for all responses:
Whenreference_textis""or whitespace-only" ",_tokenize(reference)produces[](reference_len = 0). The conditionresponse_len == 0 or reference_len == 0causes_plagiarism_scoreto silently return0.0for every response, even when the response is identical to the reference text. A static misconfiguration is thus silently swallowed and reported as non-plagiarism.
The sibling class in analytics, ApproximateTextMatching, already validates that its n-gram parameter n must be an integer >= 1.
Steps/Code to Reproduce
from pyrit.score import PlagiarismScorer, PlagiarismMetric
# 1. n=0 scores 1.0 (100% match) for completely unrelated text
scorer = PlagiarismScorer(
reference_text="The quick brown fox jumps over the lazy dog",
metric=PlagiarismMetric.JACCARD,
n=0,
)
score = scorer._plagiarism_score(
response="Completely unrelated content about astrophysics and quantum mechanics",
reference="The quick brown fox jumps over the lazy dog",
metric=PlagiarismMetric.JACCARD,
n=0,
)
print("Score with n=0:", score)
# 2. n=-1 yields spurious partial match
print(
"Score with n=-1:",
scorer._plagiarism_score(
response="Completely unrelated content",
reference="The quick brown fox jumps over the lazy dog",
metric=PlagiarismMetric.JACCARD,
n=-1,
),
)
# 3. Empty reference_text silently evaluates every response as 0.0
empty_scorer = PlagiarismScorer(reference_text="", metric=PlagiarismMetric.LCS)
print("Score with empty reference:", empty_scorer._plagiarism_score(response="", reference=""))
Expected Results
PlagiarismScorer.__init__ should validate parameters at construction time and raise ValueError:
reference_textmust be a non-empty string containing at least one word token.nmust be an integer>= 1(rejecting0, negative values, booleans, and non-integers).metricmust be an instance ofPlagiarismMetric.
Actual Results
Score with n=0: 1.0
Score with n=-1: 0.5
Score with empty reference: 0.0
PlagiarismScorer.__init__ assigns self.reference_text = reference_text and self.n = n directly at pyrit/score/float_scale/plagiarism_scorer.py:54-56 without validation.
Versions
- OS: Windows 11
- Python: 3.14
- PyRIT:
mainatc2ae5eeb
- Ngôn ngữ chính
- Python
- Star
- 4.6k
- Fork
- 944
- Merge trung bình
- 3 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 264
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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG PuzzledConverter cannot select words carrying non-ASCII letters, so the mask falls on articles insteadCó thể đã có người làm @adimalkar đã 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 74/100
microsoft/PyRIT#3022 · 2 bình luận ·
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 @rupayon123 đã nhận 14 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 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/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ự
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
hatchet-dev/hatchet#5179 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update Python support to 3.15Đang mởpython-version
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug javascript P2-medium python release:v3.1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
adrirubio/claude-deck#546 ·
Maintainer thường phản hồi trong vòng 1 ngày