harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Artem Aliev (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-2427) [luni] [compatibility] Harmony checks correctness of java.util.zip.GZIPInputStream.read(BII) arguments even if EOF was reached but RI returns -1
Date Mon, 04 Dec 2006 13:16:21 GMT
[luni] [compatibility] Harmony checks correctness of java.util.zip.GZIPInputStream.read(BII)
arguments even if EOF was reached but RI returns -1
------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-2427
                 URL: http://issues.apache.org/jira/browse/HARMONY-2427
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Artem Aliev
            Priority: Minor


According to J2SE API 5.0 specifications of java.lang.zip.GZIPInputStream
class:
public int read(byte[] buf, int off, int len) throws IOException

Returns:
    the actual number of bytes read, or -1 if the end of the compressed input 
    stream is reached 

Specification of overriden read method from IputStream class says that
method read throws IndexOutOdBoundsException when off or len is negative and
when off + len is greater than buffer length.

When the end of input stream was reached then RI returns -1 and does not
compare off+len with buf.length and does not check that off and len are 
positive.

But Harmony verifies arguments even if EOF was reached and throws 
ArrayIndexOutOfBoundsException when off or len is negative, or when off+len is
greater than array length.

Harmony unit test 
unitHarmony_org_apache_harmony_archive_tests_java_util_zip_GZIPInputStreamTest
(test_read$BII)
verifies that ArrayIndexOfBoundsException should be thrown after EOF if
off_len > buf.length.
This test fails on RI.


Code for reproducing:
To reproduce this run the following test:
--------------HT7.java--------------
import java.util.*;
import java.io.*;
import java.net.*;
import java.util.zip.*;

public class HT7 {
    public static void main (String[] args) {
        byte outBuf[] = new byte[100];
        try {
            int result = 0;                     
            URL gInput = new URL("file:hyts_gInput.txt.gz");
            GZIPInputStream inGZIP = new GZIPInputStream(
                gInput.openConnection().getInputStream());
            try {
                inGZIP.read(outBuf, 100, 1);
                System.out.println("Test failedL IOOBE was not thrown");
                return;
            } catch (IndexOutOfBoundsException e) {
                System.out.println(e + " was thrown as expected");
            }
            while (true) {
                result = inGZIP.read(outBuf, 0,5);
                if (result == -1) {
                    System.out.println("EOF was reached");
                    break;
                }
            }
            result = -10;
            try {
                result = inGZIP.read(outBuf, 100, 1);
                System.out.println("Test passed. After EOF read(buf,100,1) ==
"+result);
            } catch (IndexOutOfBoundsException e) {
                System.out.println("Test failed. After EOF read(buf, 100,1)
throws: "+e);
            }
            try {
                result = inGZIP.read(outBuf, -100, 1);
                System.out.println("Test passed. After EOF read(buf,-100,1) ==
"+result);
            } catch (IndexOutOfBoundsException e) {
                System.out.println("Test failed. After EOF read(buf,-100,1)
throws: "+e);
            }
            try {
                result = inGZIP.read(outBuf, -1, 1);//100, 1);
                System.out.println("Test passed. After EOF read(buf,1,-1) ==
"+result);
            } catch (IndexOutOfBoundsException e) {
                System.out.println("Test failed. After EOF read(buf,1,-1)
throws: "+e);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
-------------------

Steps to Reproduce:
 Create HT7 class and run it
 java -cp . HT7

Output:
On RI:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

java.lang.IndexOutOfBoundsException was thrown as expected
EOF was reached
Test passed. After EOF read(buf,100,1) == -1
Test passed. After EOF read(buf,-100,1) == -1
Test passed. After EOF read(buf,1,-1) == -1

On Harmony:
Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software
Foundation or its l
icensors, as applicable.
java version "1.5.0"
pre-alpha : not complete or compatible
svn = rsvn: '.' is not a working copy, (Sep 22 2006), Windows/ia32/msvc 1310,
debug build
http://incubator.apache.org/harmony
java.lang.ArrayIndexOutOfBoundsException was thrown as expected
EOF was reached
Test failed. After EOF read(buf, 100,1) throws:
java.lang.ArrayIndexOutOfBoundsException
Test failed. After EOF read(buf,-100,1) throws:
java.lang.ArrayIndexOutOfBoundsException
Test failed. After EOF read(buf,1,-1) throws:
java.lang.ArrayIndexOutOfBoundsException



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message