Skip to content
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

Load PSBTs using istreambuf_iterator rather than istream_iterator #687

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

achow101
Copy link
Member

istream_iterator eats whitespace charactesr which causes parsing failures for PSBTs that contain the bytes corresponding to those characters. istreambuf_iterator is the correct thing to use here.

This is a regression in 24.0. bitcoin/bitcoin#25001 accidentally changed the original istreambuf_iterator to istream_iterator.

istream_iterator eats whitespace charactesr which causes parsing
failures for PSBTs that contain the bytes corresponding to those
characters.
@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 18, 2022

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 furszy, MarcoFalke

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

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Tested ACK bb5ea1d

Not needed but wouldn't hurt to decouple the file read functionality into a util function, so this bug can be covered in a unit test.

@hebasto hebasto changed the title qt: Load PSBTs using istreambuf_iterator rather than istream_iterator Load PSBTs using istreambuf_iterator rather than istream_iterator Dec 20, 2022
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

This is a regression in 24.0.

It would be nice to add a test to prevent such a regression in the future.

@sipa @MarcoFalke

Perhaps you could be interested in reviewing of this PR as an author/a committer of bitcoin/bitcoin@a65931e in bitcoin/bitcoin#25001.

@@ -212,7 +212,7 @@ void WalletFrame::gotoLoadPSBT(bool from_clipboard)
return;
}
std::ifstream in{filename.toLocal8Bit().data(), std::ios::binary};
data.assign(std::istream_iterator<unsigned char>{in}, {});
data.assign(std::istreambuf_iterator<char>{in}, {});
Copy link
Member

@hebasto hebasto Dec 20, 2022

Choose a reason for hiding this comment

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

This change reverts bitcoin/bitcoin@a65931e partially, in particular:

  • std::istream_iterator --> std::istreambuf_iterator
  • unsigned char --> char

But the local std::vector data is still parameterized by unsigned char:

std::vector<unsigned char> data;

Is it on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that was intentional. Using unsigned char does not appear to work (fails to compile). But I don't think that data type makes a difference here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, std::ifstream is std::basic_ifstream<char>, and passing that to std::istreambuf_iterator can only be done if it is templated <char> as well. C++ (17?) derives this automatically, so you can also write:

data.assign(std::istreambuf_iterator{in}, {});

@hebasto hebasto added the Wallet label Dec 20, 2022
Copy link
Contributor

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Docs: https://en.cppreference.com/w/cpp/iterator/istream_iterator#Notes

review ACK bb5ea1d 🍇

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK bb5ea1d9a954b7b9f443ee8fbbb04549cd0b08a7   🍇
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUg34wv+NFe6qKxea+Z5Jx0PTNpbWXv+nTGMQYsOek6a+pJIe00MuJGO4XIuDJS0
Mffqqi8fhC83It02w8Z6q9zLSXB094GabCYgFanN5g0AxDdwgvjrEM5nQ9cZj3Vo
hJHDzVpdgag5i311J+05yeHig9EOnRjxBRgf1p3pv+/Tg3yS/M7UIRKdpmqAxfOA
HdPMjRQr+Tjm7+/VHwJJpEnE0fPLUZX5NjblKUmG4wDIwlcqz0qYUK8JkAtznYz9
JJvXxOayoGKNk3IF/UfZs0/cmGlPh+5AJ3asnSIizAITiwIOFaNAIUfprgc4d86V
fo66d2avigfwHVpKsLsbQep52I0deYo1dItSGvhcYxhtunB/D8eBsMi8b5kk489j
kV6i1kP/VtUVu2v2Pkgl632aupAcWM62gY3YCl50IfqNfpMgf0uG58NEScZFHmbp
920c3zvXD9n7SDx3GVQPljssLPBG7WMUfBYmwYP0NtWx28qv250dThWYnOUUoour
1GDZDw4r
=QuKV
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit 4cd6b3b into bitcoin-core:master Dec 21, 2022
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Dec 21, 2022
istream_iterator eats whitespace charactesr which causes parsing
failures for PSBTs that contain the bytes corresponding to those
characters.

Github-Pull: bitcoin-core/gui#687
Rebased-From: bb5ea1d
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 21, 2022
…er than istream_iterator

bb5ea1d qt: Load PSBTs using istreambuf_iterator rather than istream_iterator (Andrew Chow)

Pull request description:

  `istream_iterator` eats whitespace charactesr which causes parsing failures for PSBTs that contain the bytes corresponding to those characters. `istreambuf_iterator` is the correct thing to use here.

  This is a regression in 24.0. bitcoin#25001 accidentally changed the original `istreambuf_iterator` to `istream_iterator`.

ACKs for top commit:
  furszy:
    Tested ACK bb5ea1d
  MarcoFalke:
    review ACK bb5ea1d   🍇

Tree-SHA512: 35d90eee3efdcb6a360af69ac1727f9f2837ea621297196de3136299f5de6d9975df4e425e1fc5b8813c1ddb2a4d60c3969e1d5d968953a4628ca45e37d3bf05
@fanquake
Copy link
Member

Removing label as this was backported: bitcoin/bitcoin@0662105.

@bitcoin-core bitcoin-core locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants