On Fri, 30 Oct 2026 13:09:40 GMT, Timofei Fedotov <[email protected]> wrote:

>> EdDSAPublicKeyImpl(byte[]) reads the last byte of the encoded point before 
>> invoking checkLength(). An empty subjectPublicKey BIT STRING produces a 
>> zero-length array and causes an access at index -1.
>> 
>> The error is reachable through KeyFactory.generatePublic() with an 
>> X509EncodedKeySpec and through certificate parsing that decodes an EdDSA 
>> SubjectPublicKeyInfo. A minimal Ed25519 SubjectPublicKeyInfo reproducer is 
>> the DER byte sequence 300a300506032b6570030100.
>> 
>> A malformed encoded key must be rejected with the normal checked key-parsing 
>> exception rather than an array indexing exception.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Timofei Fedotov has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Update license test

test/jdk/sun/security/ec/ed/EmptyEncodedPoint.java line 40:

> 38:             byte[] encoded = HexFormat.of().parseHex("300a30050603" + oid 
> + "030100");
> 39:             try {
> 40:                 KeyFactory.getInstance("EdDSA").generatePublic(new 
> X509EncodedKeySpec(encoded));

Maybe only check the "SunEC" provider?

test/jdk/sun/security/ec/ed/EmptyEncodedPoint.java line 47:

> 45:             var pair = 
> KeyPairGenerator.getInstance(algorithm).generateKeyPair();
> 46:             KeyFactory.getInstance(algorithm).generatePublic(new 
> X509EncodedKeySpec(pair.getPublic().getEncoded()));
> 47:         }

Not necessary to include this. Should be covered in other tests.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/33641#discussion_r4445543965
PR Review Comment: https://git.openjdk.org/jdk/pull/33641#discussion_r4445550621

Reply via email to