Skip to content

Fix quadratic ReDoS in Unix-timestamp format token X - #1356

Open
jaideeppyne wants to merge 1 commit into
arrow-py:masterfrom
jaideeppyne:fix-timestamp-redos-1353
Open

jaideeppyne wants to merge 1 commit into
arrow-py:masterfrom
jaideeppyne:fix-timestamp-redos-1353

Conversation

@jaideeppyne

Copy link
Copy Markdown

Problem

arrow.get(string, "X") used _TIMESTAMP_RE = re.compile(r"^\-?\d+\.?\d+$"). The two adjacent unbounded \d+ groups separated by an optional . backtrack quadratically on digit-heavy non-matching input such as "9"*N + "x". A 40 KB payload could block a worker for ~15s.

Fix

Rewrite the regex so the fractional part is a single optional group:

_TIMESTAMP_RE = re.compile(r"^-?\d+(?:\.\d+)?$")

This is linear in the input length and still accepts integers, decimals, and negative timestamps.

Tests

  • Assert the old backtracking pattern is gone.
  • Time a 40k-digit non-match ("9"*40000 + "x") to confirm it fails quickly.
  • Confirm valid integer, fractional, and negative timestamps still parse.

Fixes #1353

The previous _TIMESTAMP_RE used two adjacent unbounded \d+ groups
separated by an optional dot, which backtracks quadratically on
digit-heavy non-matches such as "9"*N + "x".

Make the fractional part a single optional non-capturing group so
matching is linear, while still accepting integers, decimals, and
negative timestamps.
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (96e5ece).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1356   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2315           
  Branches       358       358           
=========================================
  Hits          2315      2315           

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

This branch has not been deployed

No deployments
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.

Quadratic-time ReDoS in Unix-timestamp (X) format token parsing

1 participant