refactor: replace memcpy with std::copy and add size asserts in IPC capnp serialization #35010

pull orbisai0security wants to merge 1 commits into bitcoin:master from orbisai0security:fix-fix-v-001-ipc-capnp-memcpy-bounds-check changing 1 files +5 −2
  1. orbisai0security commented at 7:18 am on April 6, 2026: none

    Summary

    Improve code quality issue in src/ipc/capnp/common-types.h.

    Description: Replacing memcpy with std.copy and adding asserts for checking buffer size. This is in the spirit of defensive programming and to improve code quality.

    Changes

    • src/ipc/capnp/common-types.h

    Automated security fix by OrbisAI Security

  2. fix: V-001 security vulnerability
    Automated security fix generated by Orbis Security AI
    50c38de124
  3. DrahtBot commented at 7:18 am on April 6, 2026: contributor

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

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  4. ViniciusCestarii commented at 12:50 pm on April 6, 2026: contributor
    The vulnerability described here doesn’t exist. output.init(stream.size()) allocates a buffer of exactly stream.size() elements, so the subsequent memcpy of stream.size() bytes is safe by construction. The sizes are equal, which is why the added assert is useless.
  5. ryanofsky commented at 1:14 pm on April 6, 2026: contributor

    Code review 50c38de1247d7c8e5dcf1bdf66df77ef10ecaee1.

    Change is reasonable but it isn’t described correctly, because it isn’t really a security fix. It is just replacing memcpy calls with std::copy calls and adding asserts that init() calls return blob builders with the correct size, which should always be the case. It is possible for the init() calls to fail if requested text or data sizes are too big, but these already trigger exceptions.

    It could be good to merge this change if the description is fixed, since probaby it is better to use std::copy and assert here. Stylistically I might also prefer:

    0-std::copy(stream.data(), stream.data() + result.size(), result.begin());
    1+std::copy(stream.data(), stream.data() + stream.size(), result.begin());
    

    but it shouldn’t make a difference

  6. DrahtBot added the label CI failed on Apr 6, 2026
  7. DrahtBot commented at 2:05 pm on April 6, 2026: contributor

    🚧 At least one of the CI tasks failed. Task 32 bit ARM: https://github.com/bitcoin/bitcoin/actions/runs/24022894521/job/70086853846 LLM reason (✨ experimental): CI failed due to a C++ compilation error: std::byte could not be converted to unsigned char while building ipc/capnp/mining.capnp.proxy-client.c++.o.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  8. orbisai0security renamed this:
    fix: multiple memcpy operations in ipc serialization... in...
    refactor: replace memcpy with std::copy and add size asserts in IPC capnp serialization
    on Apr 7, 2026
  9. orbisai0security commented at 1:43 am on April 7, 2026: none

    I’ve updated the description and title of the PR.

    I agree that it is not a security vulnerability, but rather a code quality improvement. It was indeed a false positive from our security scanner.

  10. maflcko commented at 7:46 am on April 7, 2026: member
    ai slop that doesn’t even compile
  11. maflcko closed this on Apr 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-04-08 00:13 UTC

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