Add test that extra buffer space is ignored.

Bug: 69349260
Test: vogar libcore.javax.crypto.spec.KeyFactoryTestRSA
Change-Id: I2d3560d60490f5d9710cd10d686edf8f6c6c532a
(cherry picked from commit 37f045d4742de0b0a5dfde4afb4a161d2079d5be)
diff --git a/luni/src/test/java/libcore/javax/crypto/spec/KeyFactoryTestRSA.java b/luni/src/test/java/libcore/javax/crypto/spec/KeyFactoryTestRSA.java
index d287b97..56df2bb 100644
--- a/luni/src/test/java/libcore/javax/crypto/spec/KeyFactoryTestRSA.java
+++ b/luni/src/test/java/libcore/javax/crypto/spec/KeyFactoryTestRSA.java
@@ -15,10 +15,16 @@
  */
 package libcore.javax.crypto.spec;
 
+import java.security.KeyFactory;
 import java.security.KeyPair;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.PKCS8EncodedKeySpec;
 import java.security.spec.RSAPrivateKeySpec;
 import java.security.spec.RSAPublicKeySpec;
+import java.security.spec.X509EncodedKeySpec;
 import tests.security.CipherAsymmetricCryptHelper;
+import tests.security.DefaultKeys;
 import tests.security.KeyFactoryTest;
 
 public class KeyFactoryTestRSA extends
@@ -33,4 +39,18 @@
     protected void check(KeyPair keyPair) throws Exception {
         new CipherAsymmetricCryptHelper("RSA").test(keyPair);
     }
+
+    public void testExtraBufferSpace() throws Exception {
+        PrivateKey privateKey = DefaultKeys.getPrivateKey("RSA");
+        byte[] encoded = privateKey.getEncoded();
+        byte[] longBuffer = new byte[encoded.length + 147];
+        System.arraycopy(encoded, 0, longBuffer, 0, encoded.length);
+        KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(longBuffer));
+
+        PublicKey publicKey = DefaultKeys.getPublicKey("RSA");
+        encoded = publicKey.getEncoded();
+        longBuffer = new byte[encoded.length + 147];
+        System.arraycopy(encoded, 0, longBuffer, 0, encoded.length);
+        KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(longBuffer));
+    }
 }