util: Drop boost posix_time in ParseISO8601DateTime #31391

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2411-less-boost-time changing 14 files +94 −69
  1. maflcko commented at 12:45 pm on November 28, 2024: member

    boost::posix_time in ParseISO8601DateTime has many issues:

    • It parses random strings that are clearly invalid and returns a time value for them, see [1] below.
    • None of the separators -, or :, or T, or Z are validated.
    • It may crash when running under a hardened C++ library, see #28917.
    • It has been unmaintained for years, so reporting or fixing any issues will most likely be useless.
    • It pulls in a third-party dependency, when the functionality is already included in vanilla C++20.

    Fix all issues by replacing it with a simple helper function written in C++20.

    Fixes #28917.

    [1] The following patch passes on current master:

     0diff --git a/src/wallet/test/rpc_util_tests.cpp b/src/wallet/test/rpc_util_tests.cpp
     1index 32f6f5ab46..c1c94c7116 100644
     2--- a/src/wallet/test/rpc_util_tests.cpp
     3+++ b/src/wallet/test/rpc_util_tests.cpp
     4@@ -12,6 +12,14 @@ BOOST_AUTO_TEST_SUITE(wallet_util_tests)
     5 
     6 BOOST_AUTO_TEST_CASE(util_ParseISO8601DateTime)
     7 {
     8+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("964296"), 242118028800);
     9+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("244622"), 15023836800);
    10+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("+INfINITy"), 9223372036854);
    11+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("7000802 01"), 158734166400);
    12+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("7469-2 +INfINITy"), 9223372036854);
    13+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("maXimum-datE-time"), 253402300799);
    14+    BOOST_CHECK_EQUAL(ParseISO8601DateTime("577737     114maXimum-datE-time"), 253402300799);
    15+
    16     BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0);
    17     BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0);
    18     BOOST_CHECK_EQUAL(ParseISO8601DateTime("2000-01-01T00:00:01Z"), 946684801);
    
  2. DrahtBot commented at 12:45 pm on November 28, 2024: 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/31391.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, dergoegge
    Concept ACK theStack

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label Utils/log/libs on Nov 28, 2024
  4. hebasto commented at 1:06 pm on November 28, 2024: member
    Concept ACK.
  5. maflcko commented at 3:22 pm on November 28, 2024: member

    Looks like MSVC is broken, according to the GHA run:

    0D:/a/bitcoin/bitcoin/src/test/util_tests.cpp(334): error: in "util_tests/util_ParseISO8601DateTime": check ParseISO8601DateTime("9999-12-31T23:59:59Z").value() == 253402300799 has failed [-4295736961 != 253402300799]
    

    It would be good if a someone using Windows reproduced this locally and then reported the bug to MSVC. Godbolt draft: https://godbolt.org/z/4WYn6E61W

  6. maflcko force-pushed on Nov 28, 2024
  7. maflcko force-pushed on Nov 28, 2024
  8. theStack commented at 3:45 pm on November 29, 2024: contributor
    Concept ACK
  9. maflcko added the label DrahtBot Guix build requested on Nov 29, 2024
  10. hebasto commented at 3:41 pm on December 1, 2024: member

    Looks like MSVC is broken, according to the GHA run:

    0D:/a/bitcoin/bitcoin/src/test/util_tests.cpp(334): error: in "util_tests/util_ParseISO8601DateTime": check ParseISO8601DateTime("9999-12-31T23:59:59Z").value() == 253402300799 has failed [-4295736961 != 253402300799]
    

    It would be good if a someone using Windows reproduced this locally and then reported the bug to MSVC. Godbolt draft: https://godbolt.org/z/4WYn6E61W

    See https://developercommunity.visualstudio.com/t/Unexpected-wrap-around-in-std::chrono/10803042.

  11. util: Implement ParseISO8601DateTime based on C++20 2222aecd5f
  12. maflcko commented at 7:24 am on December 2, 2024: member

    Thanks for checking! The reason is that MSVC is using int for std::chrono::minutes::rep, which is actually allowed, according to https://en.cppreference.com/w/cpp/chrono/duration#Helper_types

    I reduced it further in https://godbolt.org/z/d4TKo497e

    I pushed a workaround. If that doesn’t work, the unit test and fuzz test can be adjusted to exclude too “extreme” timepoints.

  13. maflcko force-pushed on Dec 2, 2024
  14. fanquake commented at 2:03 pm on December 2, 2024: member
    Can also drop boost-date-time from vcpkg.json.
  15. Remove wallet::ParseISO8601DateTime, use ParseISO8601DateTime instead faf70cc994
  16. maflcko force-pushed on Dec 2, 2024
  17. DrahtBot commented at 4:27 pm on December 2, 2024: contributor

    Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

    File commit dbc8ba12f3b3548dd6955293c5d650320ca39c5b(master) commit 2cce053442d98ccbf7ee87587f155b30dfd50361(master and this pull)
    SHA256SUMS.part c42e210c1e1c27a7... da5671211491f004...
    *-aarch64-linux-gnu-debug.tar.gz 2161d06927f487a9... a3632b9e2d6c8679...
    *-aarch64-linux-gnu.tar.gz 4473b2df276cabeb... 1580c32a964d6c09...
    *-arm-linux-gnueabihf-debug.tar.gz 8fac4a24bf3e43a8... 4c36f6a8861a69dc...
    *-arm-linux-gnueabihf.tar.gz c2a47ccae5350964... c94374302141cf03...
    *-arm64-apple-darwin-unsigned.tar.gz 2aa081dd171ccb49... e847cf25fac516f8...
    *-arm64-apple-darwin-unsigned.zip 9321fe827ba3c45e... 1b97c804de44d296...
    *-arm64-apple-darwin.tar.gz 874a10114c149551... 7389f55aa8b6f083...
    *-powerpc64-linux-gnu-debug.tar.gz d8e058efb356add9... 8adfc2d96cc231ff...
    *-powerpc64-linux-gnu.tar.gz 262210c4e538ea6b... a270ffb018ace747...
    *-riscv64-linux-gnu-debug.tar.gz 8b0fe23e7747da7a... 809eb70eee3e88d0...
    *-riscv64-linux-gnu.tar.gz 8524db9aca723275... b03d6cd4f68afb48...
    *-x86_64-apple-darwin-unsigned.tar.gz ee8df95ca9a29d26... 35c44d02fc38a7bc...
    *-x86_64-apple-darwin-unsigned.zip b6b61d5cae882cda... 887a9ee26818c596...
    *-x86_64-apple-darwin.tar.gz 8d97f2583b9b7a91... 255cef059c253fd1...
    *-x86_64-linux-gnu-debug.tar.gz 418699cbb53c93d7... 1f99c869684220c7...
    *-x86_64-linux-gnu.tar.gz dfb0b7df6a16399a... ed527240dfc0dc03...
    *.tar.gz eef8026aa690fbda... be0ddb3d70f35518...
    guix_build.log e0e9760e332702e1... 0c3febc7ba45a818...
    guix_build.log.diff a4804a0f37e04fb2...
  18. DrahtBot removed the label DrahtBot Guix build requested on Dec 2, 2024
  19. hebasto approved
  20. hebasto commented at 5:00 pm on December 2, 2024: member
    ACK faf70cc9941ce2b0ce4fd48ecfdbe28194adb8ba, I have reviewed the code and it looks OK.
  21. DrahtBot requested review from theStack on Dec 2, 2024
  22. dergoegge approved
  23. dergoegge commented at 10:37 am on December 3, 2024: member
    utACK faf70cc9941ce2b0ce4fd48ecfdbe28194adb8ba
  24. fanquake added this to the milestone 29.0 on Dec 3, 2024

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: 2024-12-03 18:12 UTC

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