FIX: reject non-finite AudioEcho parameters - #2566
Merged
Roman Lutz (romanlutz) merged 3 commits intoSep 10, 2026
Merged
Conversation
Roman Lutz (romanlutz)
approved these changes
Sep 10, 2026
Roman Lutz (romanlutz)
enabled auto-merge
September 10, 2026 02:04
Javier Valero (jav1er8)
added a commit
to jav1er8/PyRIT
that referenced
this pull request
Sep 10, 2026
…nverters microsoft#2560 fixed AudioSpeedConverter and microsoft#2566 fixed AudioEchoConverter by rejecting non-finite values. The same validation pattern is used across the converter family, and four converters still have the gap: `x <= 0 or x > N` never rejects NaN, because every comparison against NaN is false. Four parameters accepted NaN and/or infinity before this change: AudioWhiteNoiseConverter.noise_scale NaN AudioVolumeConverter.volume_factor NaN, inf ImageColorSaturationConverter.level NaN, inf ImageRotationConverter.angle NaN, inf (never validated at all) The audio and image converters then corrupt their output silently, which matters for a red-teaming tool: the artifact is written, stored in memory and sent to the target as if it were valid. AudioWhiteNoiseConverter(noise_scale=nan) rng.normal(0, nan * max_val) makes the whole array NaN. np.clip does not repair NaN, and the int16 cast turns it into zeros — silent audio, no error. AudioVolumeConverter(volume_factor=inf) 0 * inf = nan on silent samples, everything else saturates. ImageColorSaturationConverter(level=nan), ImageRotationConverter(angle=nan) PIL returns an all-black image. No exception. Adds math.isfinite to each validation and validates ImageRotationConverter.angle, which had no check. Error messages now name finiteness, so the existing tests that match on them are updated the same way microsoft#2560 and microsoft#2566 updated theirs. Tests follow the parametrized pattern introduced in microsoft#2560 and cover nan, inf and -inf for every affected parameter.
Contributor
Author
|
Thanks, Roman Lutz (@romanlutz), for reviewing and merging this and #2563! |
Contributor
|
Thank YOU for the contribution! Sylvester Kaczmarek (@sylvesterkaczmarek) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
AudioEchoConvertervalidates the numeric ranges ofdelayanddecay, but IEEE-754 NaN passes ordinary range comparisons.delay=float("nan")therefore constructs successfully and fails later when the converter calculates the integer delay in samples, while non-finite decay values can propagate invalid audio data.This change requires both parameters to be finite in addition to their existing range constraints:
delaymust be finite and greater than zero.decaymust be finite and strictly between zero and one.Invalid configuration now fails immediately with a clear
ValueError.Tests
Adds regression coverage for NaN, positive infinity and negative infinity for both
delayanddecay, while preserving the existing zero, negative and out-of-range validation.