fuzz: refactor memcpy to std::ranges::copy to work around ubsan warn #33743

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2510-fuzz-refactor-memcpy changing 1 files +6 −5
  1. maflcko commented at 10:10 am on October 30, 2025: member

    Using std::ranges::copy from the C++ standard library has a few benefits here:

    • It has the additional benefit of being a bit more type safe and document the byte cast explicitly.
    • The compiler will likely optimize it to the same asm, but performance doesn’t really matter here anyway.
    • It has defined semantics for empty source ranges.

    Fixes https://github.com/bitcoin/bitcoin/issues/33643

  2. fuzz: refactor memcpy to std::ranges::copy to work around ubsan warn
    Using std::ranges::copy from the C++ standard library has a few benefits
    here:
    
    * It has the additional benefit of being a bit more type safe and
      document the byte cast explicitly.
    * The compiler will likely optimize it to the same asm, but performance
      doesn't really matter here anyway.
    * It works around an UB-Sanitizer bug, when the source range is empty.
    
    Fixes https://github.com/bitcoin/bitcoin/issues/33643
    fa4b52bd16
  3. DrahtBot added the label Tests on Oct 30, 2025
  4. DrahtBot commented at 10:10 am on October 30, 2025: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK marcofleon, dergoegge

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  5. maflcko added this to the milestone 31.0 on Oct 30, 2025
  6. fanquake commented at 10:11 am on October 30, 2025: member
  7. maflcko force-pushed on Oct 30, 2025
  8. purpleKarrot commented at 1:30 pm on October 30, 2025: contributor
    • It works around an UB-Sanitizer bug, when the source range is empty.

    I guess what you want to express is:

    • It has defined semantics for empty source ranges.

    Passing a zero length to memcpy is UB per the language standard. This is not an “UB-Sanitizer bug”.

  9. fanquake added the label Fuzzing on Oct 30, 2025
  10. maflcko commented at 2:18 pm on October 30, 2025: member

    Yeah, I guess it is too early to call this a bug, but the language standard has been changed, see #33644 (comment).

    I’ve used your wording for now.

  11. marcofleon commented at 3:01 pm on October 30, 2025: contributor

    tACK fa4b52bd16189d40761c5976b8427e30779aba23

    Tested this branch and didn’t see the null pointer error. The change to std::byte is for modernization and the change to std::ranges addresses the issue.

  12. dergoegge approved
  13. dergoegge commented at 9:54 am on October 31, 2025: member
    utACK fa4b52bd16189d40761c5976b8427e30779aba23
  14. fanquake merged this on Oct 31, 2025
  15. fanquake closed this on Oct 31, 2025

  16. maflcko deleted the branch on Oct 31, 2025

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: 2025-11-20 15:13 UTC

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