--timeout-factor accepts NaN, Infinity, and overflowed floats

Open Beginner friendly
#35 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli

Research direction

Start in src/mutator/cli.py at the --timeout-factor validation in parse_args (around lines 219-225), and check src/mutator/engine.py _apply_selected only to confirm how the factor feeds the timeout. Run the reproduction in the issue to see nan, inf and 1e309 accepted. Done when those values return a usage error, zero, negative and finite values still parse, and parameterized tests in tests/test_boundaries.py cover them.

Written by the indexing model from the issue text.

Description

Summary

--timeout-factor checks only whether float(value) <= 0. NaN and positive infinity bypass that check, including overflowed numeric input such as 1e309. The resulting mutant timeout is not a meaningful finite factor of baseline duration.

Verified on main at 830ec7e9c39664d753f8699015bc796df67727b9 with Python 3.14.8. No package installation is required for this reproduction.

Minimal reproduction

Run with Python 3.11+ and Git. This uses only disposable fixture files and does not install or invoke the mutator launcher.

work=$(mktemp -d)
git clone https://github.com/unclebob/mutator.git "$work/mutator"
cd "$work/mutator"
git checkout 830ec7e9c39664d753f8699015bc796df67727b9
python3 -B - <<'PY'
"""Run from a mutator checkout using Python 3.11+; standard library only."""
import ast
import math
import sys
from dataclasses import dataclass, field
from pathlib import Path

path = Path('src/mutator/cli.py')
tree = ast.parse(path.read_text())
names = {'Options', '_take', '_workers', '_lines', 'parse_args'}
module = ast.parse('from __future__ import annotations')
module.body += [n for n in tree.body if isinstance(n, (ast.FunctionDef, ast.ClassDef)) and n.name in names]
g = dict(__name__='__main__', dataclass=dataclass, field=field, Path=Path, sys=sys, HELP='')
exec(compile(module, str(path), 'exec'), g)
engine = ast.parse(Path('src/mutator/engine.py').read_text())
apply = next(n for n in engine.body if isinstance(n, ast.FunctionDef) and n.name == '_apply_selected')
assignment = next(n for n in apply.body if isinstance(n, ast.Assign)
                  and any(isinstance(t, ast.Name) and t.id == 'timeout' for t in n.targets))
timeout_code = compile(ast.Expression(assignment.value), 'engine.py', 'eval')
for value in ('nan', 'NaN', 'inf', 'Infinity', '1e309'):
    options = g['parse_args'](['--timeout-factor', value])
    assert options.action == 'mutate' and options.exit_code == 0
    assert not math.isfinite(options.timeout_factor)
    timeout = eval(timeout_code, {'seconds': 0.5, 'timeout_factor': options.timeout_factor})
    print(f'{value}: accepted; factor={options.timeout_factor}; mutant_timeout={timeout}')
for value in ('0', 'invalid'):
    assert g['parse_args'](['--timeout-factor', value]).exit_code == 1
print('controls: zero and invalid text rejected')
PY

This standard-library probe executes the actual Options and argument parser definitions extracted with ast, then evaluates the actual timeout assignment expression extracted from _apply_selected. It does not start a potentially unbounded process or claim any particular platform-specific subprocess behavior for infinity.

Observed output

nan: accepted; factor=nan; mutant_timeout=2.0
NaN: accepted; factor=nan; mutant_timeout=2.0
inf: accepted; factor=inf; mutant_timeout=inf
Infinity: accepted; factor=inf; mutant_timeout=inf
1e309: accepted; factor=inf; mutant_timeout=inf
controls: zero and invalid text rejected

Expected behavior

Reject nonfinite timeout factors as usage errors, alongside zero and negative values. Require math.isfinite(factor) and factor > 0 before running coverage or tests.

Actual behavior

nan and NaN are accepted and produce the 2-second floor for a 0.5-second baseline. inf, Infinity, and 1e309 are accepted and produce an infinite timeout. Zero and nonnumeric text are rejected as controls.

Regression test

Parameterize parser tests over nan, NaN, inf, Infinity, +inf, and 1e309 and assert a usage error. Keep positive finite factors accepted, with zero and negative values rejected. Separately verify calculated deadlines remain finite if overflow of a large finite factor is supported.

The reproduction asserts the currently observed defect. A regression test should invert the defective-behavior assertions to enforce the expected behavior.

Source

Related #1 concerns cold worker compilation exceeding an ordinary finite timeout. It does not report nonfinite argument acceptance. No genuine duplicate found.

Dominant language
Python
Stars
112
Forks
53
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from unclebob/mutator

All issues in unclebob/mutator

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.