United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7172149 ArrayIndexOutOfBoundsException from Signature.verify
JDK-7172149 : ArrayIndexOutOfBoundsException from Signature.verify

Details
Type:
Bug
Submit Date:
2012-05-28
Status:
Closed
Updated Date:
2012-09-04
Project Name:
JDK
Resolved Date:
2012-09-04
Component:
security-libs
OS:
linux
Sub-Component:
java.security
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Ubuntu 12.04 LTS

A DESCRIPTION OF THE PROBLEM :
If a call to java.security.Signature.verify(byte[] signature,  int offset, int length) with offset + length > Integer.MAX_VALUE, an ArrayIndexOutOfBoundsException will be thrown instead of IllegalArgumentException.

REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test finished silently.
ACTUAL -
 java.lang.ArrayIndexOutOfBoundsException was thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2147483648
	at sun.security.util.DerInputStream.init(DerInputStream.java:106)
	at sun.security.util.DerInputStream.<init>(DerInputStream.java:95)
	at sun.security.provider.DSA.engineVerify(DSA.java:326)
	at java.security.Signature$Delegate.engineVerify(Signature.java:1179)
	at java.security.Signature.verify(Signature.java:665)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

/*
 * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * Portions Copyright (c) 2012 IBM Corporation
 */
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PublicKey;
import java.security.Signature;

public class test {

    public static void main(String[] args) throws Exception {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
        keyPairGenerator.initialize(1024);
        KeyPair keys = keyPairGenerator.generateKeyPair();
        PublicKey publicKey = keys.getPublic();
        byte[] sigBytes = new byte[100];

        Signature signature = Signature.getInstance("SHA1withDSA");
        signature.initVerify(publicKey);
        try {
            signature.verify(sigBytes, Integer.MAX_VALUE, 1);
        } catch (IllegalArgumentException ex) {
            // Expected
        }
    }
}
---------- END SOURCE ----------

                                    

Comments
EVALUATION

take care of the integer addition overflow
                                     
2012-06-07
EVALUATION

Source change looks good:
http://hg.openjdk.java.net/jdk8/tl/jdk/rev/713b10821c3d

And the test for this is passing now:
http://aurora.ru.oracle.com/functional/faces/RunDetails.xhtml?names=92444.CORELIBS-JDK8-NIGHTLY-JTREG-13
                                     
2012-08-28



Hardware and Software, Engineered to Work Together