Skip to content

fix(drivingDistance): raise error on negative distance input#3105

Open
aki1770-del wants to merge 1 commit intopgRouting:mainfrom
aki1770-del:fix/driving-distance-negative-guard-3091
Open

fix(drivingDistance): raise error on negative distance input#3105
aki1770-del wants to merge 1 commit intopgRouting:mainfrom
aki1770-del:fix/driving-distance-negative-guard-3091

Conversation

@aki1770-del
Copy link
Copy Markdown

Summary

pgr_drivingDistance and pgr_drivingDistanceWithPoints silently returned an empty result set when called with a negative distance value. An empty result is indistinguishable from a valid empty-graph result — callers have no way to detect the misconfiguration.

The develop branch (4.1.0-dev) already raises ERROR: Negative value found on 'distance' via src/spanningTree/spanningTree_process.cpp:105-106. This PR backports the equivalent guard to main.

Fix

Added a negative-distance guard in pgr_do_drivingDistance and pgr_do_drivingDistanceWithPoints (both C++ drivers) before graph query execution:

if (distance < 0) {
    *err_msg = to_pg_msg("Negative value found on 'distance'");
    *log_msg = to_pg_msg("distance must be non-negative");
    return;
}

Existing behavior audit (OPS-RULE-016)

  • src/driving_distance/driving_distance_driver.cpp: no distance validation before graph construction; negative values silently traverse an empty Dijkstra result
  • src/driving_distance/driving_distance_withPoints_driver.cpp: same pattern, same missing guard
  • src/spanningTree/spanningTree_process.cpp (develop branch, line 105-106): contains the fix; does not exist on main

Scope classification (OPS-RULE-017)

(a) Bug fix — missing input validation that causes silent incorrect behavior.

Prior art consulted (OPS-RULE-018)

  1. develop branch src/spanningTree/spanningTree_process.cpp:82-106 — the exact validation pattern this fix mirrors for the main branch
  2. Issue #3091 — bug report with reproduce steps and confirmation of the develop-vs-main discrepancy
  3. pgtap/dijkstra/driving_distance/edge_cases/issue_519.pg — existing edge-case test pattern followed for the new issue_3091.pg test

Test evidence

Added pgtap/dijkstra/driving_distance/edge_cases/issue_3091.pg:

  • Asserts throws_ok for distance = -1.0
  • Asserts distance = 0.0 returns only the origin node (valid edge case)

AI-assisted — authored with Claude, reviewed by Komada.

…ng#3091)

pgr_drivingDistance and pgr_drivingDistanceWithPoints silently returned
an empty result set when called with a negative distance value. This
was indistinguishable from a valid empty-graph result, masking routing
configuration bugs.

Fix: add a negative-distance guard in both drivers before graph query
execution, consistent with the validation already present in develop
branch (src/spanningTree/spanningTree_process.cpp:105-106).

Adds pgTap regression test in edge_cases/issue_3091.pg.

Fixes pgRouting#3091

Co-Authored-By: Claude and aki1770-del <aki1770@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 125f9102-ca83-4a72-800b-f9386ec3950e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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