Skip to content

FIX: reject non-finite parameters in the remaining audio and image converters - #2613

Open
Javier Valero (jav1er8) wants to merge 1 commit into
microsoft:mainfrom
jav1er8:fix/non-finite-converter-parameters
Open

FIX: reject non-finite parameters in the remaining audio and image converters#2613
Javier Valero (jav1er8) wants to merge 1 commit into
microsoft:mainfrom
jav1er8:fix/non-finite-converter-parameters

Conversation

@jav1er8

@jav1er8 Javier Valero (jav1er8) commented Sep 9, 2026

Copy link
Copy Markdown

Follow-up to #2560 (AudioSpeed) and #2566 (AudioEcho). 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.

Parameters that accept non-finite values on main

Converter Parameter NaN inf
AudioWhiteNoiseConverter noise_scale accepted rejected
AudioVolumeConverter volume_factor accepted accepted
ImageColorSaturationConverter level accepted accepted
ImageRotationConverter angle accepted accepted

ImageRotationConverter.angle has no validation at all.

Why it matters

The output is corrupted silently, which is the bad case 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) and ImageRotationConverter(angle=nan) — PIL returns an all-black image, no exception.

Changes

math.isfinite in each validation, plus a finiteness check on ImageRotationConverter.angle. Error messages now name finiteness, so the existing tests matching on them are updated the same way #2560 and #2566 updated theirs.

Tests follow the parametrized pattern introduced in #2560 and cover nan, inf and -inf for every affected parameter.

Verification

  • pytest tests/unit/converter: 1476 passed, 34 skipped
  • ruff format --check, ruff check, ty check: clean

Note on scope

This PR originally also covered AudioEchoConverter. #2566 landed that while this was open, so those two files were dropped on rebase and main's version kept — see the comment below.

@jav1er8

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

…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.
@jav1er8
Javier Valero (jav1er8) force-pushed the fix/non-finite-converter-parameters branch from a7e4de3 to 82265a5 Compare September 10, 2026 07:05
@jav1er8

Copy link
Copy Markdown
Author

Rebased onto main and narrowed the scope.

#2566 landed the AudioEcho half of this while the PR was open, so delay and decay are already fixed upstream. I dropped my version of those two files entirely and kept main's — my changes there were only different wording of the same fix, and rewording error messages in an already-fixed file would be gratuitous churn.

What remains is the four converters that are still unguarded on main:

Converter Parameter NaN inf
AudioWhiteNoiseConverter noise_scale accepted rejected
AudioVolumeConverter volume_factor accepted accepted
ImageColorSaturationConverter level accepted accepted
ImageRotationConverter angle accepted accepted

ImageRotationConverter.angle still has no validation at all.

Now +57/-21 across 8 files instead of +86/-33 across 10. pytest tests/unit/converter is green (1476 passed, 34 skipped), ruff format --check and ruff check clean.

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.

1 participant