Skip to content

Spark name overflow fix - #1851

Merged
reubenyap merged 2 commits into
masterfrom
sparknames-overflow-fix
May 22, 2026
Merged

Spark name overflow fix#1851
reubenyap merged 2 commits into
masterfrom
sparknames-overflow-fix

Conversation

@psolstice

Copy link
Copy Markdown
Contributor

PR intention

Fixed a bug that may cause the spark name validity overflow over INT_MAX in some cases

Code changes brief

Additional checks to test if the added number of blocks is within the bounds

@codeant-ai

codeant-ai Bot commented May 19, 2026

Copy link
Copy Markdown

User peter@shugalev.com does not have a PR Review subscription.

Go to Team management and add this email to the PR Review subscription.

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 40e8923d-2fc9-4fcf-948b-8ee08ad20f41

📥 Commits

Reviewing files that changed from the base of the PR and between 8379839 and 914c742.

📒 Files selected for processing (2)
  • src/sparkname.cpp
  • src/test/sparkname_tests.cpp

Summary by CodeRabbit

  • Bug Fixes

    • Added integer overflow protection for spark name validity period calculations to prevent potential errors when handling extended renewal periods exceeding the 15-year limit.
  • Tests

    • Added comprehensive test coverage to verify overflow protection functions correctly for edge cases.

Walkthrough

This PR adds integer overflow protection to sparkname validity validation. Two validation functions now explicitly check that sparkNameValidityBlocks does not exceed a 15-year block limit before narrowing from uint32_t to int, preventing overflow in dependent calculations. A comprehensive test validates that overflow-triggering values are rejected while normal operations remain functional.

Changes

Sparkname Validity Overflow Protection

Layer / File(s) Summary
Transaction validation bounds check
src/sparkname.cpp
CheckSparkNameTx adds an explicit uint32_t range check on sparkNameValidityBlocks before converting to int, returning a DoS error if the 15-year limit is exceeded to prevent integer overflow in remaining-time calculations.
V2.1 data validation overflow guard
src/sparkname.cpp
ValidateSparkNameData replaces direct int computation with a guarded flow: first validates sparkNameValidityBlocks against the 15-year per-purchase limit, then computes total validity (including remaining blocks from existing registration) with overflow-preventing checks.
Overflow protection test coverage
src/test/sparkname_tests.cpp
New validity_overflow_protection test confirms that registration/renewal with overflow-triggering uint32_t values (INT_MAX + 1u, UINT32_MAX) are rejected at block generation, and that standard 1-year renewals continue to succeed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • levonpetrosyan93
  • aleflm
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Spark name overflow fix' directly summarizes the main change in the changeset, which addresses integer overflow issues in spark name validity calculations.
Description check ✅ Passed The pull request description includes both required sections (PR intention and Code changes brief) with substantive information about the bug fix and the bounds checks added.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sparknames-overflow-fix

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.

@reubenyap
reubenyap merged commit 4190608 into master May 22, 2026
37 of 39 checks passed
@reubenyap
reubenyap deleted the sparknames-overflow-fix branch May 22, 2026 14:40
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.

2 participants