Skip to content

fix(probes): guard badchars ASCII selection against max_ascii_variants=1 - #2012

Open
manunicholasjacob wants to merge 1 commit into
NVIDIA:mainfrom
manunicholasjacob:fix/badchars-single-ascii-variant
Open

fix(probes): guard badchars ASCII selection against max_ascii_variants=1#2012
manunicholasjacob wants to merge 1 commit into
NVIDIA:mainfrom
manunicholasjacob:fix/badchars-single-ascii-variant

Conversation

@manunicholasjacob

Copy link
Copy Markdown

What this changes

BadCharacters._select_ascii() divides by limit - 1:

if limit is None or limit <= 0 or limit >= len(ASCII_PRINTABLE):
    return list(ASCII_PRINTABLE)
step = max(1, (len(ASCII_PRINTABLE) - 1) // (limit - 1))

limit == 1 passes both guards, so the division raises ZeroDivisionError.
max_ascii_variants is configurable via DEFAULT_PARAMS, so setting it to 1
prevents the probe from constructing.

_select_positions() in the same class already handles the equivalent case:

if cap == 1:
    return [positions[0]]

This adds the matching guard to _select_ascii().

Reproduction

probes:
  badchars:
    BadCharacters:
      max_ascii_variants: 1

fails at probe construction with integer division or modulo by zero. Values
of 2 and above work as expected.

Testing

Adds tests/probes/test_probes_badchars.py covering limits 1, 2 and 3. The
limit-1 case fails on main and passes with this change.

_select_ascii divided by (limit - 1) after guards that let limit == 1
through, so the user-settable max_ascii_variants=1 raised ZeroDivisionError
at probe construction. The sibling _select_positions in the same class
already special-cases cap == 1; mirror that.

Signed-off-by: manunicholasjacob <manunicholasjacob@gmail.com>
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