Skip to content

verify() with an empty signature throws FFI\Exception instead of OqsException #3

Open

Description

@dstebila
$sig = new OqsSig('ML-DSA-65');
$keys = $sig->generateKeypair();

$sig->verify('msg', '', $keys['public_key']);
// FFI\Exception: Cannot instantiate FFI\CData of zero size

verify() allocates the signature buffer with $ffi->new('uint8_t[' . strlen($signature) . ']'), and PHP FFI rejects a zero-size allocation.

This matters because the README documents verify() as "Never throws for an invalid signature — only for malformed input lengths", and signatures are attacker-controlled input. Code following that contract with catch (OqsException) won't contain the exception, so an empty signature becomes an uncaught fatal error.

The message buffer already handles this case:

$msgBuf = $ffi->new('uint8_t[' . max(1, strlen($message)) . ']');

The same treatment applied to the signature buffer (passing the real length to OQS_SIG_verify separately) fixes it. An explicit length check that returns false would work too — a zero-length signature is never valid for any supported algorithm.

Non-empty malformed signatures behave correctly: a 1-byte signature and an oversized signature both return false as expected.

Reproduced with liboqs 0.16.0 (shared build), PHP 8.5.8 with FFI, macOS/arm64.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions