Skip to content

mpgen: Work around c++20 / capnproto 0.8 incompatibility #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ryanofsky
Copy link
Collaborator

Fix ubuntu 22.04 compatibility issue reported by fanquake in bitcoin/bitcoin#33176 and add CI job to make sure libmultiprocess stays compatible with old versions of Cap'n Proto.

Changes are described in more detail in commit messages.

@DrahtBot
Copy link

DrahtBot commented Aug 12, 2025

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Sjors

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

@ryanofsky
Copy link
Collaborator Author

ryanofsky commented Aug 12, 2025

Updated 151ef65 -> c659685 (pr/string.1 -> pr/string.2, compare) testing some more intermediate versions
Updated c659685 -> 88d9504 (pr/string.2 -> pr/string.3, compare) adding missing file

rev = "v${capnprotoVersion}";
hash = lib.attrByPath [capnprotoVersion] "" capnprotoHashes;
};
patches = lib.optionals (lib.versionAtLeast capnprotoVersion "0.9.0" && lib.versionOlder capnprotoVersion "0.10.4") [ ./ci/patches/spaceship.patch ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

88d9504: do I read this correctly as: apply patch to versions 0.9.0 <= ... < 0.10.4?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #194 (comment)

88d9504: do I read this correctly as: apply patch to versions 0.9.0 <= ... < 0.10.4?

Yes that's right. These versions of capnproto added some c++20 support which didn't actually work with later compiler versions.

@Sjors
Copy link
Member

Sjors commented Aug 13, 2025

utACK 88d9504

The kj/string.h header installed by capnproto 0.8 doesn't work well when
compiling with -std=c++20 or later because the reverse StringPtr/char*
comparison function it provides is broken in c++20:

inline bool operator==(const char* a, const StringPtr& b) { return b == a; }

Before C++20 this would implicitly convert `a` to a StringPtr and call the
StringPtr::operator== method. But starting with C++20 it actually calls itself
recursively and either loops forever or crashes.

This problem was fixed upstream by
capnproto/capnproto#1170 in Cap'n Proto 0.9.0. Avoid
the problem here for older versions by just not using the operator. A CI job
testing older versions is added in the next commit to avoid similar breakage in
the future.
The CI job currently just tests old Cap'n Proto versions, but it might be nice
to extend in the future to test old compilers & build tools too.

Support for versions of Cap'n Proto before 0.7.0 was dropped in
bitcoin-core#88 in order to avoid
compiler warnings and simplify code. Before that, versions back to 0.5 were
supported and are basically still compatible since the Cap'n Proto API hasn't
changed and libmultiprocess does not rely on newer features.
ryanofsky added a commit that referenced this pull request Aug 13, 2025
30930df build: require CapnProto 0.7.0 or better (Sjors Provoost)

Pull request description:

  Although 1.0.1. is the oldest version currently covered by Bitcoin Core's extensive CI, Debian Bookwork ships 0.9.2 and #194 introduces test coverage for even older versions. 0.7 has been required since #88.

  The CI run of Sjors/bitcoin#100 @ [3d55222](https://github.com/Sjors/bitcoin/pull/100/checks?sha=3d552223712eed88d17e5ead1ef7d1ba6fd7e89e) previously checked Bitcoin Core CI against 1.0.1 as the minimum. Lowering the minimum further should not be a problem for that CI.

ACKs for top commit:
  ryanofsky:
    Code review ACK 30930df. Planning to follow up in #194 to actually test minimum version and error if capnproto version detected is affected by CVE-2022-46149

Tree-SHA512: bed5843973c8ff1f0b2bd93efe7169824c2306097efefaace1752efeb06606df765b68b7ef50c07f5d703010c4d1b324099d6780fa0363e126d34ac1307fba1a
Also document minimum Cap'n Proto version in doc/install.md
Copy link
Collaborator Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased 88d9504 -> dc3ba22 (pr/string.3 -> pr/string.4, compare) on top of #193 and added explicit check for CVE-2022-46149

rev = "v${capnprotoVersion}";
hash = lib.attrByPath [capnprotoVersion] "" capnprotoHashes;
};
patches = lib.optionals (lib.versionAtLeast capnprotoVersion "0.9.0" && lib.versionOlder capnprotoVersion "0.10.4") [ ./ci/patches/spaceship.patch ];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #194 (comment)

88d9504: do I read this correctly as: apply patch to versions 0.9.0 <= ... < 0.10.4?

Yes that's right. These versions of capnproto added some c++20 support which didn't actually work with later compiler versions.

@Sjors
Copy link
Member

Sjors commented Aug 13, 2025

utACK dc3ba22

Thanks for adding the CVE version check.

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.

3 participants