From: Kevin J. B. <kev...@us...> - 2003-01-03 00:49:37
|
Update of /cvsroot/jython/jython/org/python/core In directory sc8-pr-cvs1:/tmp/cvs-serv12834/org/python/core Modified Files: SyspathJavaLoader.java imp.java Added Files: FileUtil.java Log Message: [511493] Prevent truncation of large file loads, especially in jreload, but also in other locations that loaded only the available bytes. --- NEW FILE: FileUtil.java --- // Copyright (c) 2003 Jython project package org.python.core; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; /** * Utility methods for Java file handling. */ public class FileUtil { /** * Read all bytes from the input stream. * * Note that using this method to read very large streams could * cause out-of-memory exceptions and/or block for large periods * of time. */ public static byte[] readBytes( InputStream in ) throws IOException { final int bufsize = 8192; // nice buffer size used in JDK byte[] buf = new byte[ bufsize ]; ByteArrayOutputStream out = new ByteArrayOutputStream( bufsize ); int count; while( true ) { count = in.read( buf, 0, bufsize ); if ( count < 0 ) break; out.write( buf, 0, count ); } return out.toByteArray(); } } Index: SyspathJavaLoader.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/SyspathJavaLoader.java,v retrieving revision 2.5 retrieving revision 2.6 diff -C2 -d -r2.5 -r2.6 *** SyspathJavaLoader.java 28 Oct 2001 17:13:43 -0000 2.5 --- SyspathJavaLoader.java 3 Jan 2003 00:49:34 -0000 2.6 *************** *** 108,114 **** } try { ! int size = fis.available(); ! byte[] buffer = new byte[size]; ! fis.read(buffer); fis.close(); return loadClassFromBytes(name, buffer); --- 108,112 ---- } try { ! byte[] buffer = FileUtil.readBytes( fis ); fis.close(); return loadClassFromBytes(name, buffer); Index: imp.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/imp.java,v retrieving revision 2.63 retrieving revision 2.64 diff -C2 -d -r2.63 -r2.64 *** imp.java 30 May 2002 19:20:29 -0000 2.63 --- imp.java 3 Jan 2003 00:49:34 -0000 2.64 *************** *** 28,38 **** } - // Simplistic implementation - // Some InputStream's might require multiple read's to get it all... private static byte[] readBytes(InputStream fp) { try { ! byte[] buf; ! buf = new byte[fp.available()]; ! fp.read(buf); fp.close(); return buf; --- 28,34 ---- } private static byte[] readBytes(InputStream fp) { try { ! byte[] buf = FileUtil.readBytes( fp ); fp.close(); return buf; |