Skip to content

Commit a37dccd

Browse files
FIX: validate UnicodeSubstitution start value (#2559)
Co-authored-by: Roman Lutz <romanlutz13@gmail.com>
1 parent 681482f commit a37dccd

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎pyrit/converter/unicode_sub_converter.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ def __init__(self, *, start_value: int = 0xE0000) -> None:
2020
2121
Args:
2222
start_value (int): The unicode starting point to use for encoding.
23+
24+
Raises:
25+
ValueError: If ``start_value`` is outside the Unicode code point range.
2326
"""
27+
if not 0 <= start_value <= 0x10FFFF:
28+
raise ValueError("start_value must be a valid Unicode code point between 0 and 0x10FFFF")
2429
self.startValue = start_value
2530

2631
def _build_identifier(self) -> ComponentIdentifier:

‎tests/unit/converter/test_unicode_sub_converter.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ async def test_unicode_sub_custom_start():
2222
assert result.output_type == "text"
2323

2424

25+
@pytest.mark.parametrize("start_value", [-1, 0x110000])
26+
def test_unicode_sub_rejects_invalid_start_value(start_value):
27+
with pytest.raises(ValueError, match="valid Unicode code point"):
28+
UnicodeSubstitutionConverter(start_value=start_value)
29+
30+
2531
async def test_unicode_sub_empty():
2632
converter = UnicodeSubstitutionConverter()
2733
result = await converter.convert_async(prompt="", input_type="text")

0 commit comments

Comments
 (0)