Skip to content

CMR-11378: StackOverFlow error in cmr search - #2533

Merged
daniel-zamora merged 3 commits into
masterfrom
CMR-11378
Nov 5, 2026
Merged

daniel-zamora merged 3 commits into
masterfrom
CMR-11378

Conversation

@daniel-zamora

@daniel-zamora daniel-zamora commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Overview

What is the objective?

Large polygon and line search params return a 500. The regex that validates them recurses once per point and overflows the stack at around 450 points, fewer in prod. Lines under 4500 characters have the same problem.

What are the changes?

  • Polygon and line params are validated by splitting on commas and matching each ordinate, so stack depth no longer grows with point count. Lines use the same rule at every length, which removes the 4500-character branch.
  • New max-polygon-points config (CMR_MAX_POLYGON_POINTS, default 1000). A polygon over the limit returns a 400, the same as max-line-points. The overflow used to cap polygons by accident, and validation cost grows with the square of the point count (5000 points takes about 3.4 s of search-app CPU), so the cap is now explicit.
  • max-line-points now applies to every line, not only lines over 4500 characters.
  • Long lines with trailing commas or numbers that aren't plain decimals (NaN, exponents, whitespace) now return a 400, matching short lines and polygons.
  • Added unit and int tests for large shapes and the limits. The API docs now state the polygon limit.
  • Polygon and line params are rejected for too many points before they are split or parsed, so oversized input (up to the 50 MB body limit) fails fast instead of allocating alot of memory.

What areas of the application does this impact?

  • spatial-lib: codec, messages
  • search-app: polygon and line params on collection, granule and tile searches
  • search-app API docs

Required Checklist

  • New and existing unit and int tests pass locally and remotely
  • clj-kondo has been run locally and all errors in changed files are corrected
  • I have commented my code, particularly in hard-to-understand areas
  • I have made changes to the documentation (if necessary)
  • My changes generate no new warnings

Additional Checklist

  • I have removed unnecessary/dead code and imports in files I have changed
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • reduced number of system state resets by updating fixtures. Ex) (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

@daniel-zamora daniel-zamora changed the title Cmr 11378 CMR-11378: StackOverFlow error in cmr search Nov 3, 2026
@codecov-commenter

codecov-commenter commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.41%. Comparing base (cc5a76c) to head (4d881d6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2533      +/-   ##
==========================================
- Coverage   54.41%   54.41%   -0.01%     
==========================================
  Files        1047     1047              
  Lines       73542    73542              
  Branches     2410     2409       -1     
==========================================
- Hits        40018    40017       -1     
  Misses      31248    31248              
- Partials     2276     2277       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

(index/wait-until-indexed)
(is (d/refs-match? [whole-world]
(search/find-refs-with-post :collection {:polygon large-polygon
:provider "PROV1"})))))

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.

We could add an assertion that a polygon exceeding max-polygon-points returns a 400

@daniel-zamora
daniel-zamora merged commit 6cc551e into master Nov 5, 2026
6 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.

4 participants