FIX: reject non-finite parameters in the remaining audio and image converters - #2613
Open
Javier Valero (jav1er8) wants to merge 1 commit into
Open
Conversation
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.
Javier Valero (jav1er8)
force-pushed
the
fix/non-finite-converter-parameters
branch
from
September 10, 2026 07:05
a7e4de3 to
82265a5
Compare
Author
|
Rebased onto #2566 landed the AudioEcho half of this while the PR was open, so What remains is the four converters that are still unguarded on
Now +57/-21 across 8 files instead of +86/-33 across 10. |
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.
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 > Nnever rejects NaN, because every comparison against NaN is false.Parameters that accept non-finite values on
mainAudioWhiteNoiseConverternoise_scaleAudioVolumeConvertervolume_factorImageColorSaturationConverterlevelImageRotationConverterangleImageRotationConverter.anglehas 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.clipdoes not repair NaN, and the int16 cast turns it into zeros. Silent audio, no error.AudioVolumeConverter(volume_factor=inf)—0 * inf = nanon silent samples, everything else saturates.ImageColorSaturationConverter(level=nan)andImageRotationConverter(angle=nan)— PIL returns an all-black image, no exception.Changes
math.isfinitein each validation, plus a finiteness check onImageRotationConverter.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,infand-inffor every affected parameter.Verification
pytest tests/unit/converter: 1476 passed, 34 skippedruff format --check,ruff check,ty check: cleanNote on scope
This PR originally also covered
AudioEchoConverter. #2566 landed that while this was open, so those two files were dropped on rebase andmain's version kept — see the comment below.