tests: add coverage for exact-size DER signature serialization
What changed, and why it matters
This commit only adds a new test case. It checks that a DER signature can be written into a buffer that is exactly the right size, and that writing into a buffer one byte too small fails correctly. There is no change to the actual library code that handles signatures, so this does not fix or introduce a security issue by itself.
No security action needed; treat as routine test-coverage improvement. If reviewing a larger series, consider whether this test was added because a prior commit changed serialization behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a boundary-condition test in src/tests.c inside test_ecdsa_end_to_end. It serializes a parsed DER ECDSA signature into a 74-byte buffer, confirms the length matches the original, compares bytes, then retries with a buffer length one byte smaller and verifies the function returns 0 while still reporting the required size. The underlying serialization function is unchanged.
Changed components
src/tests.cInspect captured patch +12 / −0
### src/tests.c
@@ -6828,6 +6828,18 @@ static void test_ecdsa_end_to_end(void) {
memset(&signature[0], 0, sizeof(signature[0]));
CHECK(secp256k1_ecdsa_signature_parse_der(CTX, &signature[0], sig, siglen) == 1);
CHECK(secp256k1_ecdsa_verify(CTX, &signature[0], message, &pubkey) == 1);
+ /* Serializing into a buffer of exactly the required size succeeds and
+ * yields the same encoding; one byte less fails and reports the size. */
+ {
+ unsigned char sig2[74];
+ size_t siglen2 = siglen;
+ CHECK(secp256k1_ecdsa_signature_serialize_der(CTX, sig2, &siglen2, &signature[0]) == 1);
+ CHECK(siglen2 == siglen);
+ CHECK(secp256k1_memcmp_var(sig2, sig, siglen) == 0);
+ siglen2 = siglen - 1;
+ CHECK(secp256k1_ecdsa_signature_serialize_der(CTX, sig2, &siglen2, &signature[0]) == 0);
+ CHECK(siglen2 == siglen);
+ }
/* Serialize/destroy/parse DER and verify again. */
siglen = 74;
CHECK(secp256k1_ecdsa_signature_serialize_der(CTX, sig, &siglen, &signature[0]) == 1);Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.