rpc: avoid descriptor range counter overflow #35872

pull l0rinc wants to merge 2 commits into bitcoin:master from l0rinc:l0rinc/descriptor-range-counter-overflow changing 2 files +3 −1
  1. l0rinc commented at 10:03 PM on August 3, 2026: contributor

    Problem: The authenticated scantxoutset, scanblocks, getdescriptoractivity, utxoupdatepsbt, and descriptorprocesspsbt RPCs share a descriptor expansion helper that iterates inclusive int64_t ranges with an int counter. A ranged descriptor with an explicit [begin, end] range ending at 2^31 - 1 expands that valid position, then overflows when advancing the counter to exit the loop. Trap-enabled builds terminate, while other builds invoke undefined behavior.

    Fix: Use int64_t for loop control so the one-past-the-end value is representable and every position passed to Descriptor::Expand() remains within its existing int range.

    Related: #26275 fixed the same endpoint overflow in deriveaddresses.

  2. test: characterize descriptor range endpoint 143a13fb2b
  3. rpc: avoid descriptor range counter overflow
    Descriptor ranges may end at `INT32_MAX`, but the expansion loop counts with `int`.
    Incrementing after the final index overflows, terminating the node in `-ftrapv` builds and invoking undefined behavior otherwise.
    
    Use `int64_t` so the final increment stays representable.
    264555af3c
  4. DrahtBot added the label RPC/REST/ZMQ on Aug 3, 2026
  5. DrahtBot commented at 10:04 PM on August 3, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35872.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK polespinasa, sedited, achow101

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. polespinasa commented at 10:31 PM on August 3, 2026: member

    ACK 264555af3cc2ab2919e49e7dea3f8066b9336020

    code lgtm, good catch. ~I couldn't test it with the test introduced here, it does not fail for me.~ Edit: nevermind I am blind... I was not compiling in debug mode lol. Tested ACK :)

  7. sedited approved
  8. sedited commented at 9:04 AM on August 4, 2026: contributor

    ACK 264555af3cc2ab2919e49e7dea3f8066b9336020

  9. achow101 commented at 7:34 PM on August 6, 2026: member

    ACK 264555af3cc2ab2919e49e7dea3f8066b9336020

  10. achow101 merged this on Aug 6, 2026
  11. achow101 closed this on Aug 6, 2026

  12. maflcko added the label Needs Backport (31.x) on Aug 7, 2026
  13. maflcko removed the label Needs Backport (31.x) on Aug 7, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-14 17:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me