test/jdk/java/io/CharArrayReader/OverflowInRead.java
author tschatzl
Wed, 24 Jul 2019 11:49:39 +0200
changeset 57508 28ab01c06755
parent 47216 71c04702a3d5
permissions -rw-r--r--
8228388: Add information about dirty/skipped card for Merge HCC in G1 log Summary: Collect and print informatio about the number of processed cards during the Merge HCC phase to improve log output. Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40263
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     1
/*
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     4
 *
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     8
 *
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    13
 * accompanied this code).
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    14
 *
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    18
 *
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    21
 * questions.
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    22
 */
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    23
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    24
/* @test
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    25
 * @bug 8163518
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    26
 * @summary Integer overflow when reading in large buffer
40265
e73a9c4ada83 8163877: Tests added in JDK-8163518 fail on some platforms
igerasim
parents: 40263
diff changeset
    27
 * @requires (sun.arch.data.model == "64" & os.maxMemory > 8g)
40263
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    28
 * @run main/othervm -Xmx8g OverflowInRead
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    29
 */
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    30
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    31
import java.io.CharArrayReader;
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    32
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    33
public class OverflowInRead {
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    35
        char[] a = "_123456789_123456789_123456789_123456789"
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    36
                .toCharArray(); // a.length > 33
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    37
        try (CharArrayReader car = new CharArrayReader(a)) {
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    38
            int len1 = 33;
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    39
            char[] buf1 = new char[len1];
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    40
            if (car.read(buf1, 0, len1) != len1)
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    41
                throw new Exception("Expected to read " + len1 + " chars");
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    42
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    43
            int len2 = Integer.MAX_VALUE - 32;
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    44
            char[] buf2 = new char[len2];
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    45
            int expLen2 = a.length - len1;
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    46
            if (car.read(buf2, 0, len2) != expLen2)
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    47
                throw new Exception("Expected to read " + expLen2 + " chars");
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    48
        }
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    49
    }
6d435de7abbc 8163518: Integer overflow in StringBufferInputStream.read() and CharArrayReader.read/skip()
igerasim
parents:
diff changeset
    50
}