-
Notifications
You must be signed in to change notification settings - Fork 25
Possible crash when (not) writing the compact size of the script/prevector #122
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
Comments
You can reproduce with bitcoin/bitcoin#30437 and diff --git a/src/bitcoin-mine.cpp b/src/bitcoin-mine.cpp
index 4d5faea23e..08281b57d4 100644
--- a/src/bitcoin-mine.cpp
+++ b/src/bitcoin-mine.cpp
@@ -120,5 +120,7 @@ MAIN_FUNCTION
tfm::format(std::cout, "Tip hash is null.\n");
}
+ (void)mining->createNewBlock({});
+
return EXIT_SUCCESS;
} |
@maflcko does it crash with |
Yes, with:
|
I'm guessing serialization code is confused by CScript being convertible to a span of bytes but also having serialize and deserialize methods. So it is being sent as raw bytes: which receiving code tries to pass to Unserialize Probably the easiest way to fix this would be to add a Alternately, it might make sense for cscript to have a |
I am not sure about fixing this with additional bandages on top. If code can lead to runtime errors, it should ideally fail compilation in the first place. Otherwise, this seems like a cat-and-mouse game where a user runs into a random crash and then has to wait for developers to fix it in the next release, if it is reported at all. Or even worse, a roundrtip mismatch will silently corrupt the data. My suggested fix would be:
|
Those are good thoughts. I do think this problem is mostly just caused by the unusual Another possible improvement and fix could be to change capnp proto schema. Instead of allowing bitcoin serialization be applied to any capnp The fix you suggest also could make sense but I would have to think more about how to implement it. |
BuildField definition was moved from https://github.com/bitcoin/bitcoin/blob/0a931a9787b196d7a620863cc143d9319ffd356d/src/ipc/capnp/common-types.h#L137-L162 and tweaked to be more restrictive so it only matches `LocalType`'s that are convertible to spans and constructible from spans, not just types that are convertible to spans. This allows adding a matching CustomReadField function below, which is new. Having the CustomReadField function fixes a serialization bug in the bitcoin core mining IPC interface that was reported in Sjors/bitcoin#71 and bitcoin-core#122 The bug was caused by not having CustomBuildField and CustomReadField paired together, so a lower priority CustomReadField was chosen that was not compatible.
BuildField definition was moved from https://github.com/bitcoin/bitcoin/blob/0a931a9787b196d7a620863cc143d9319ffd356d/src/ipc/capnp/common-types.h#L137-L162 and tweaked to be more restrictive so it only matches `LocalType`'s that are convertible to spans and constructible from spans, not just types that are convertible to spans. This allows adding a matching CustomReadField function below, which is new. Having the CustomReadField function fixes a serialization bug in the bitcoin core mining IPC interface that was reported in Sjors/bitcoin#71 and bitcoin-core#122 The bug was caused by not having CustomBuildField and CustomReadField paired together, so a lower priority CustomReadField was chosen that was not compatible.
Add regression test for serialization bug in IPC mining code that is not currently being called anywhere reported: Sjors#71 bitcoin-core/libmultiprocess#122
Add regression test for serialization bug in IPC mining code that is not currently being called anywhere reported: Sjors#71 bitcoin-core/libmultiprocess#122
Add regression test for serialization bug in IPC mining code that is not currently being called anywhere reported: Sjors#71 bitcoin-core/libmultiprocess#122
Add regression test for serialization bug in IPC mining code that is not currently being called anywhere reported: #71 bitcoin-core/libmultiprocess#122
Discovered while testing the Template Provider.
Sjors/bitcoin#71 (comment)
There's a chance this bug isn't in multiprocess but in a rebasing or other mistake on my end, but it's probably worth looking into.
The text was updated successfully, but these errors were encountered: