tests: add coverage for exact-size DER signature serialization #1928

pull brunoerg wants to merge 1 commits into bitcoin-core:master from brunoerg:2026-09-test-ecdsa-buffer-exactly changing 1 files +12 −0
  1. brunoerg commented at 8:20 PM on September 3, 2026: contributor

    The existing tests only serialize into oversized buffers or one that is far too small, so the boundary case where the output buffer is exactly the required size was untested. Check that this succeeds with identical output, and that one byte less fails while reporting the required size.

    Kills the following mutant (https://secp256k1.space/src/ecdsa_impl.h#1141):

    diff --git a/src/ecdsa_impl.h b/src/ecdsa_impl.h
    index 5963877..499fe03 100644
    --- a/src/ecdsa_impl.h
    +++ b/src/ecdsa_impl.h
    @@ -176,7 +176,7 @@ static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const
         secp256k1_scalar_get_b32(&s[1], as);
         while (lenR > 1 && rp[0] == 0 && rp[1] < 0x80) { lenR--; rp++; }
         while (lenS > 1 && sp[0] == 0 && sp[1] < 0x80) { lenS--; sp++; }
    -    if (*size < 6+lenS+lenR) {
    +    if (*size <= 6+lenS+lenR) {
             *size = 6 + lenS + lenR;
             return 0;
         }
    
  2. tests: add coverage for exact-size DER signature serialization
    The existing tests only serialize into oversized buffers or one that is
    far too small, so the boundary case where the output buffer is exactly
    the required size was untested. Check that this succeeds with identical
    output, and that one byte less fails while reporting the required size.
    500ccb60f7
  3. real-or-random approved
  4. real-or-random commented at 12:03 PM on September 4, 2026: contributor

    utACK 500ccb60f70550332adf6b6f894ce84659cd6831

    thanks!

  5. real-or-random added the label assurance on Sep 4, 2026
  6. real-or-random added the label tweak/refactor on Sep 4, 2026
  7. theStack approved
  8. theStack commented at 5:03 AM on September 7, 2026: contributor

    ACK 500ccb60f70550332adf6b6f894ce84659cd6831

    Thanks for killing another 🧟 👌

  9. real-or-random merged this on Sep 7, 2026
  10. real-or-random closed this on Sep 7, 2026

  11. brunoerg deleted the branch on Sep 7, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-09-09 02:15 UTC

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