You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jan Steuerwald (Created) (JIRA)" <ji...@apache.org> on 2012/02/13 09:16:59 UTC

[jira] [Created] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
-----------------------------------------------------------------------------------------------

                 Key: IO-302
                 URL: https://issues.apache.org/jira/browse/IO-302
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 2.1
         Environment: Win7 64bit, Java 6 32bit
            Reporter: Jan Steuerwald


Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.

The following test code reveals the problem:

{code:title=Test.java}
import java.io.InputStream;

import org.apache.commons.io.input.BOMInputStream;

public class Test {

	public static void main(String[] args) {
		try {
			// read the file with BOM twice - works
			readFile("testfileWithBOM.xml");
			// read the file without BOM twice - crashes
			readFile("testfileWithoutBOM.xml");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void readFile(String testFile) throws Exception {

		InputStream inputStream = Test.class.getClassLoader().getResourceAsStream(testFile);
		BOMInputStream bomStream = new BOMInputStream(inputStream);

		bomStream.mark(1000000);
		// read for the first time => ok
		int bytes = 0;
		byte[] bytesFromStream = new byte[100];
		do {
			bytes = bomStream.read(bytesFromStream);
		} while (bytes > 0);

		// reset and read a second time => crashes when file has no BOM
		bomStream.reset();
		do {
			bytes = bomStream.read(bytesFromStream);
		} while (bytes > 0);
	}
}
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Jan Steuerwald (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jan Steuerwald updated IO-302:
------------------------------

    Attachment: Test.java
    
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>         Attachments: Test.java, testfileBOM.xml, testfileNoBOM.xml
>
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The following test code reveals the problem:
> {code:title=Test.java}
> import java.io.InputStream;
> import org.apache.commons.io.input.BOMInputStream;
> public class Test {
> 	public static void main(String[] args) {
> 		try {
> 			// read the file with BOM twice - works
> 			readFile("testfileWithBOM.xml");
> 			// read the file without BOM twice - crashes
> 			readFile("testfileWithoutBOM.xml");
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 	}
> 	private static void readFile(String testFile) throws Exception {
> 		InputStream inputStream = Test.class.getClassLoader().getResourceAsStream(testFile);
> 		BOMInputStream bomStream = new BOMInputStream(inputStream);
> 		bomStream.mark(1000000);
> 		// read for the first time => ok
> 		int bytes = 0;
> 		byte[] bytesFromStream = new byte[100];
> 		do {
> 			bytes = bomStream.read(bytesFromStream);
> 		} while (bytes > 0);
> 		// reset and read a second time => crashes when file has no BOM
> 		bomStream.reset();
> 		do {
> 			bytes = bomStream.read(bytesFromStream);
> 		} while (bytes > 0);
> 	}
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Jan Steuerwald (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jan Steuerwald updated IO-302:
------------------------------

    Description: 
Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.

The attached test case reveals the problem.

  was:
Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.

The following test code reveals the problem:

{code:title=Test.java}
import java.io.InputStream;

import org.apache.commons.io.input.BOMInputStream;

public class Test {

	public static void main(String[] args) {
		try {
			// read the file with BOM twice - works
			readFile("testfileWithBOM.xml");
			// read the file without BOM twice - crashes
			readFile("testfileWithoutBOM.xml");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void readFile(String testFile) throws Exception {

		InputStream inputStream = Test.class.getClassLoader().getResourceAsStream(testFile);
		BOMInputStream bomStream = new BOMInputStream(inputStream);

		bomStream.mark(1000000);
		// read for the first time => ok
		int bytes = 0;
		byte[] bytesFromStream = new byte[100];
		do {
			bytes = bomStream.read(bytesFromStream);
		} while (bytes > 0);

		// reset and read a second time => crashes when file has no BOM
		bomStream.reset();
		do {
			bytes = bomStream.read(bytesFromStream);
		} while (bytes > 0);
	}
}
{code}

    
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>         Attachments: Test.java, testfileBOM.xml, testfileNoBOM.xml
>
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The attached test case reveals the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Gary D. Gregory (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved IO-302.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.2
         Assignee: Gary D. Gregory

In SVN.
                
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>            Assignee: Gary D. Gregory
>             Fix For: 2.2
>
>         Attachments: IO-302.patch, Test.java, testfileBOM.xml, testfileNoBOM.xml
>
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The attached test case reveals the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Marcos Vinícius da Silva (Updated JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marcos Vinícius da Silva updated IO-302:
----------------------------------------

    Attachment: IO-302.patch

Hi all!
Please, take a look for this correction.
I cleaned up the test case to make it more clear and cut the sample file.
                
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>         Attachments: IO-302.patch, Test.java, testfileBOM.xml, testfileNoBOM.xml
>
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The attached test case reveals the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Jan Steuerwald (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jan Steuerwald updated IO-302:
------------------------------

    Attachment: testfileNoBOM.xml
                testfileBOM.xml
    
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>         Attachments: Test.java, testfileBOM.xml, testfileNoBOM.xml
>
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The following test code reveals the problem:
> {code:title=Test.java}
> import java.io.InputStream;
> import org.apache.commons.io.input.BOMInputStream;
> public class Test {
> 	public static void main(String[] args) {
> 		try {
> 			// read the file with BOM twice - works
> 			readFile("testfileWithBOM.xml");
> 			// read the file without BOM twice - crashes
> 			readFile("testfileWithoutBOM.xml");
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 	}
> 	private static void readFile(String testFile) throws Exception {
> 		InputStream inputStream = Test.class.getClassLoader().getResourceAsStream(testFile);
> 		BOMInputStream bomStream = new BOMInputStream(inputStream);
> 		bomStream.mark(1000000);
> 		// read for the first time => ok
> 		int bytes = 0;
> 		byte[] bytesFromStream = new byte[100];
> 		do {
> 			bytes = bomStream.read(bytesFromStream);
> 		} while (bytes > 0);
> 		// reset and read a second time => crashes when file has no BOM
> 		bomStream.reset();
> 		do {
> 			bytes = bomStream.read(bytesFromStream);
> 		} while (bytes > 0);
> 	}
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Gary D. Gregory (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory closed IO-302.
------------------------------


Version 2.2 has been released and addresses this issue.
                
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>            Assignee: Gary D. Gregory
>             Fix For: 2.2
>
>         Attachments: IO-302.patch, Test.java, testfileBOM.xml, testfileNoBOM.xml
>
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The attached test case reveals the problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (IO-302) ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times

Posted by "Gary D. Gregory (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13207028#comment-13207028 ] 

Gary D. Gregory commented on IO-302:
------------------------------------

Could post this as a unit test patch file with a license grant to Apache (this can be done by selecting the check-box when you attach a file). Supplying the test files will help too. Thank you!
                
> ArrayIndexOutOfBoundsException in BOMInputStream when reading a file without BOM multiple times
> -----------------------------------------------------------------------------------------------
>
>                 Key: IO-302
>                 URL: https://issues.apache.org/jira/browse/IO-302
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>         Environment: Win7 64bit, Java 6 32bit
>            Reporter: Jan Steuerwald
>
> Resetting the BOMInputStream doesn't reset the _fbLength_ member variable. This causes _fbLength_ to grow bigger than the _firstBytes_ array (when the file doesn't contain a BOM), which leads to an ArrayIndexOutOfBoundsException in the _readFirstBytes_ method.
> The following test code reveals the problem:
> {code:title=Test.java}
> import java.io.InputStream;
> import org.apache.commons.io.input.BOMInputStream;
> public class Test {
> 	public static void main(String[] args) {
> 		try {
> 			// read the file with BOM twice - works
> 			readFile("testfileWithBOM.xml");
> 			// read the file without BOM twice - crashes
> 			readFile("testfileWithoutBOM.xml");
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 	}
> 	private static void readFile(String testFile) throws Exception {
> 		InputStream inputStream = Test.class.getClassLoader().getResourceAsStream(testFile);
> 		BOMInputStream bomStream = new BOMInputStream(inputStream);
> 		bomStream.mark(1000000);
> 		// read for the first time => ok
> 		int bytes = 0;
> 		byte[] bytesFromStream = new byte[100];
> 		do {
> 			bytes = bomStream.read(bytesFromStream);
> 		} while (bytes > 0);
> 		// reset and read a second time => crashes when file has no BOM
> 		bomStream.reset();
> 		do {
> 			bytes = bomStream.read(bytesFromStream);
> 		} while (bytes > 0);
> 	}
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira