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

Aperta Adatta ai principianti
#35 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Inizia da src/mutator/cli.py alla validazione di --timeout-factor in parse_args (circa righe 219-225) e controlla _apply_selected in src/mutator/engine.py solo per confermare come il fattore alimenta il timeout. Esegui la riproduzione nell'issue per vedere che nan, inf e 1e309 vengono accettati. È completato quando questi valori restituiscono un errore di utilizzo, zero, valori negativi e valori finiti continuano a essere analizzati, e i test parametrizzati in tests/test_boundaries.py li coprono.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
112
Fork
53
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di unclebob/mutator

Tutte le issue di unclebob/mutator

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.