{"record":{"id":"c9f780cd8b50a726","repo":"lcobucci/jwt","slug":"invalid-data-should-contain-an-integer","errorCode":null,"errorMessage":"Invalid data. Should contain an integer.","messagePattern":"Invalid data\\. Should contain an integer\\.","errorType":"exception","errorClass":"Lcobucci\\JWT\\Signer\\Ecdsa\\ConversionFailed","httpStatus":null,"severity":"error","filePath":"src/Signer/Ecdsa/MultibyteStringConverter.php","lineNumber":129,"sourceCode":"        $points = hex2bin(str_pad($pointR, $length, '0', STR_PAD_LEFT) . str_pad($pointS, $length, '0', STR_PAD_LEFT));\n        assert(is_string($points));\n        assert($points !== '');\n\n        return $points;\n    }\n\n    private static function readAsn1Content(string $message, int &$position, int $length): string\n    {\n        $content   = substr($message, $position, $length);\n        $position += $length;\n\n        return $content;\n    }\n\n    private static function readAsn1Integer(string $message, int &$position): string\n    {\n        if (self::readAsn1Content($message, $position, self::BYTE_SIZE) !== self::ASN1_INTEGER) {\n            throw ConversionFailed::integerExpected();\n        }\n\n        $length = (int) hexdec(self::readAsn1Content($message, $position, self::BYTE_SIZE));\n\n        return self::readAsn1Content($message, $position, $length * self::BYTE_SIZE);\n    }\n\n    private static function retrievePositiveInteger(string $data): string\n    {\n        while (\n            substr($data, 0, self::BYTE_SIZE) === self::ASN1_NEGATIVE_INTEGER\n            && substr($data, 2, self::BYTE_SIZE) > self::ASN1_BIG_INTEGER_LIMIT\n        ) {\n            $data = substr($data, 2, null);\n        }\n\n        return $data;\n    }","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/lcobucci/jwt/blob/375813049c24c7111bda8b6884c57b071ceb2fe7/src/Signer/Ecdsa/MultibyteStringConverter.php#L111-L147","documentation":"Thrown by the private readAsn1Integer helper when, while parsing a DER ECDSA signature inside fromAsn1, the next byte is not the ASN.1 INTEGER tag (0x02). A valid DER signature is a SEQUENCE of exactly two INTEGERs (r and s); anything else means the data is malformed.","triggerScenarios":"Calling fromAsn1() with a DER blob whose SEQUENCE contents are not two INTEGER elements — e.g. corrupted data, wrong ASN.1 structure (e.g. a certificate or public key passed instead of a signature), or data truncated mid-sequence.","commonSituations":"Passing a DER public key or certificate instead of a DER signature, manually crafted ASN.1 payloads, or a bit-flip corruption during transmission.","solutions":["Verify the input is a DER ECDSA signature (SEQUENCE of two INTEGERs), not another DER structure","Check the signature was not truncated or modified in transit","Confirm you are not passing a certificate or public key where a signature is expected","Regenerate the signature from the original signer"],"exampleFix":"// before\n$raw = $converter->fromAsn1($derPublicKeyPemBody, 32); // wrong input\n// after\n$raw = $converter->fromAsn1($derSignature, 32);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { $raw = $converter->fromAsn1($der, $length); } catch (\\Jose\\Component\\Signature\\Exception\\ConversionFailed $e) { return false; /* invalid signature input */ }","preventionTips":["Sanitize signature input at the boundary (length + DER tag checks)","Never pass certificates or keys into signature converters","Treat conversion failure as an invalid-token signal in verification paths"],"tags":["ecdsa","asn1","der","parsing"],"backgroundTag":"schema-validation-failed","analyzedSha":"375813049c24c7111bda8b6884c57b071ceb2fe7","analyzedAt":"2026-09-14T11:12:28.004Z","contentChangedAt":"2026-09-14T11:12:28.004Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}