Skip to content

FIX: reject non-finite AudioEcho parameters - #2566

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/audio-echo-finite-params
Sep 10, 2026
Merged

FIX: reject non-finite AudioEcho parameters#2566
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/audio-echo-finite-params

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Description

AudioEchoConverter validates the numeric ranges of delay and decay, 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:

  • delay must be finite and greater than zero.
  • decay must 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 delay and decay, while preserving the existing zero, negative and out-of-range validation.

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Sep 10, 2026
Merged via the queue into microsoft:main with commit 8206900 Sep 10, 2026
55 checks passed
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.
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Thanks, Roman Lutz (@romanlutz), for reviewing and merging this and #2563!

@romanlutz

Copy link
Copy Markdown
Contributor

Thank YOU for the contribution! Sylvester Kaczmarek (@sylvesterkaczmarek)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants