Skip to content

fix(comparators): raise ValueError for out-of-range or non-string config (#663) - #667

Merged
digalaviz merged 2 commits into
awslabs:devfrom
digalaviz:fix/comparator-config-overflow
Dec 1, 2026
Merged

digalaviz merged 2 commits into
awslabs:devfrom
digalaviz:fix/comparator-config-overflow

Conversation

@digalaviz

Copy link
Copy Markdown
Contributor

tl;dr for humans

Fixes #663. PointDistanceComparator(max_distance=10**400) raised OverflowError and AngleComparator(angle_unit=["degrees"]) raised TypeError. Both now raise the documented ValueError.


for agents

  • intent: every invalid constructor argument of the two comparators added in feat(comparators): add PointDistanceComparator for 2D and 3D points #632 and feat(comparators): add AngleComparator for wraparound angles #633 (both unreleased) raises ValueError.
  • code:
    • point_distance.py: convert max_distance to float once; an int beyond float range maps to inf and fails the same finite check. The stored value is always a float.
    • angle.py: reject a non-string angle_unit before the lookup.
  • commits:
    • fix(comparators): reject an out-of-range int max_distance with ValueError
    • fix(comparators): reject a non-string angle_unit with ValueError (with its CHANGELOG line)
  • verification:
    • new tests fail on dev (4 failed: 10**400, 2**1024, -10**400, list angle_unit) and pass with the fix; a test pins that an int max_distance is stored as a float.
    • full suite with -n auto: 6756 passed, 13 skipped, 1 xfailed. ruff check clean.
    • tests/integrations (Strands Evals contract): 641 passed, 1 skipped.
    • checked by an independent adversarial review.

…rror

- math.isfinite() converts an int to float, so 10**400, 2**1024 or
  -10**400 raised OverflowError instead of the documented ValueError
- convert once under try/except OverflowError, then check the float,
  the same way _normalize_point already handles coordinates
- pin that an int max_distance is stored as a float
- the dict membership check raised TypeError for an unhashable value
  such as a list; the docstring promises ValueError for any invalid
  angle_unit
- the changelog entry for the unreleased AngleComparator now says so
@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-28T04:48:36+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-28T04:44:47+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 0 0 0 7534 0 0 PASSED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 0 0 0 0 0 0 PASSED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 6 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Report generated by Automated Security Helper (ASH) at 2026-11-28T04:48:37+00:00

@vawsgit vawsgit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM!

I tested head b10eb20 against origin/dev (0a4820f). origin/dev is also the merge base, so the branch is current.

What I checked:

  • The cases from #663. All five now raise ValueError: max_distance=10**400, 2**1024 and inf, and angle_unit=["degrees"] and "deg". On dev, the two big ints raised OverflowError and the list raised TypeError.
  • Values that worked before still work. I ran 32 inputs through both constructors and through create_comparator on dev and on this head, then diffed the output. Only the intended cases changed: big positive and negative ints, 2**1024-1, and a list or dict angle_unit.
    • Still accepted: int, float, np.float64, int and float subclasses, 2**1023, 5e-324, "radians", a str-Enum member, np.str_.
    • Still rejected: True, None, "10", NaN, "Degrees", np.int64, Fraction, Decimal.
  • Config and registry. A 400-digit integer loaded with json.loads now raises ValueError. The field converter wraps it the same way it wraps "deg". config still round-trips: {'max_distance': 5.0}.
  • Tests. The two changed test files pass (65 tests). The full suite with -n auto gives 6756 passed, 13 skipped and 1 xfailed, which matches the PR body. Ruff and CI are clean.
  • Mutation tests. Every new test fails when I break the fix it covers.
    • Restoring dev's two source files fails 4 tests: 10**400, 2**1024, -10**400 and the list angle_unit.
    • Removing only except OverflowError fails the 3 big-int tests.
    • Storing the raw max_distance instead of the float fails test_int_max_distance_is_stored_as_float.
  • Linked issue. #663 asks only for max_distance and angle_unit to raise ValueError, and this PR does both, so Fixes #663 is correct. The CHANGELOG entry follows the repo's format.

Optional, not blocking:

  • point_distance.py#L80-L82 puts {max_distance!r} in the message. For an int of more than 4300 digits, building that repr fails, so PointDistanceComparator(max_distance=10**5000) shows ValueError: Exceeds the limit (4300 digits) for integer string conversion... instead of your message. The error is still a ValueError, so the contract this PR promises holds.
  • FuzzyComparator has the same bug in code this PR does not touch: FuzzyComparator(method=["ratio"]) raises TypeError: unhashable type: 'list'. #663 does not cover it, so it could be a follow-up issue.

@digalaviz digalaviz added this to the 1.1.0 milestone Dec 1, 2026
@digalaviz
digalaviz merged commit ddd0315 into awslabs:dev Dec 1, 2026
11 checks passed
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.

[BUG]: PointDistanceComparator and AngleComparator raise OverflowError and TypeError for invalid config instead of ValueError

2 participants