Changeset f2ae1bf


Ignore:
Timestamp:
Feb 15, 2017 4:45:06 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
8a89b3d
Parents:
17b781c1
Message:

Utils: Disable caching of ResettableGZIPOutputStreams,
add more checks for compression failure,
fix output for zero-length input (ticket #1915)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    r17b781c1 rf2ae1bf  
    16281628    /**
    16291629     *  Compress the data and return a new GZIP compressed byte array.
     1630     *  The compressed data conforms to RFC 1952,
     1631     *  with a 10-byte gzip header and a 8-byte gzip checksum footer.
     1632     *
     1633     *  Prior to 0.9.29, this would return a zero-length output
     1634     *  for a zero-length input. As of 0.9.29, output is valid for
     1635     *  a zero-length input also.
     1636     *
    16301637     *  @throws IllegalArgumentException if input size is over 40KB
     1638     *  @throws IllegalStateException on compression failure, as of 0.9.29
     1639     *  @return null if orig is null
    16311640     */
    16321641    public static byte[] compress(byte orig[]) {
     
    16361645    /**
    16371646     *  Compress the data and return a new GZIP compressed byte array.
     1647     *  The compressed data conforms to RFC 1952,
     1648     *  with a 10-byte gzip header and a 8-byte gzip checksum footer.
     1649     *
     1650     *  Prior to 0.9.29, this would return a zero-length output
     1651     *  for a zero-length input. As of 0.9.29, output is valid for
     1652     *  a zero-length input also.
     1653     *
    16381654     *  @throws IllegalArgumentException if size is over 40KB
     1655     *  @throws IllegalStateException on compression failure, as of 0.9.29
     1656     *  @return null if orig is null
    16391657     */
    16401658    public static byte[] compress(byte orig[], int offset, int size) {
     
    16441662    /**
    16451663     *  Compress the data and return a new GZIP compressed byte array.
     1664     *  The compressed data conforms to RFC 1952,
     1665     *  with a 10-byte gzip header and a 8-byte gzip checksum footer.
     1666     *
     1667     *  Prior to 0.9.29, this would return a zero-length output
     1668     *  for a zero-length input. As of 0.9.29, output is valid for
     1669     *  a zero-length input also.
     1670     *
    16461671     *  @throws IllegalArgumentException if size is over 40KB
     1672     *  @throws IllegalStateException on compression failure, as of 0.9.29
     1673     *  @param level the compression level, 0 to 9
     1674     *  @return null if orig is null
    16471675     */
    16481676    public static byte[] compress(byte orig[], int offset, int size, int level) {
    1649         if ((orig == null) || (orig.length <= 0)) return orig;
     1677        if (orig == null) return orig;
    16501678        if (size > MAX_UNCOMPRESSED)
    16511679            throw new IllegalArgumentException("tell jrandom size=" + size);
     
    16601688            //    _log.debug("Compression of " + orig.length + " into " + rv.length + " (or " + 100.0d
    16611689            //               * (((double) orig.length) / ((double) rv.length)) + "% savings)");
     1690
     1691            // ticket 1915
     1692            // If we have a bug where the deflator didn't flush, this will catch it.
     1693            // gzip header is 10 bytes and footer is 8 bytes.
     1694            // size for zero-length input is 20.
     1695            if (rv.length <= 18)
     1696                throw new IllegalStateException("Compression failed, input size: " + size + " output size: " + rv.length);
    16621697            return rv;
    16631698        } catch (IOException ioe) {
     
    16691704            //   ...
    16701705            ioe.printStackTrace();
    1671             return null;
     1706            throw new IllegalStateException("Compression failed, input size: " + size, ioe);
    16721707        } finally {
    16731708            ReusableGZIPOutputStream.release(out);
     
    16781713    /**
    16791714     *  Decompress the GZIP compressed data (returning null on error).
    1680      *  @throws IOException if uncompressed is over 40 KB
     1715     *  @throws IOException if uncompressed is over 40 KB,
     1716     *                      or on a decompression error
     1717     *  @return null if orig is null
    16811718     */
    16821719    public static byte[] decompress(byte orig[]) throws IOException {
     
    16861723    /**
    16871724     *  Decompress the GZIP compressed data (returning null on error).
    1688      *  @throws IOException if uncompressed is over 40 KB
     1725     *  @throws IOException if uncompressed is over 40 KB,
     1726     *                      or on a decompression error
     1727     *  @return null if orig is null
    16891728     */
    16901729    public static byte[] decompress(byte orig[], int offset, int length) throws IOException {
    1691         if ((orig == null) || (orig.length <= 0)) return orig;
     1730        if (orig == null) return orig;
    16921731        if (offset + length > orig.length)
    16931732            throw new IOException("Bad params arrlen " + orig.length + " off " + offset + " len " + length);
  • core/java/src/net/i2p/util/ReusableGZIPOutputStream.java

    r17b781c1 rf2ae1bf  
    2121    // Apache Harmony 5.0M13 Deflater doesn't work after reset()
    2222    // Neither does Android
    23     private static final boolean ENABLE_CACHING = !(SystemVersion.isApache() ||
    24                                                     SystemVersion.isAndroid());
     23    // attempt to fix #1915
     24    //private static final boolean ENABLE_CACHING = !(SystemVersion.isApache() ||
     25    //                                                SystemVersion.isAndroid());
     26    private static final boolean ENABLE_CACHING = false;
    2527    private static final LinkedBlockingQueue<ReusableGZIPOutputStream> _available;
    2628    static {
  • history.txt

    r17b781c1 rf2ae1bf  
     12017-02-15 zzz
     2 * Utils: Disable caching of ResettableGZIPOutputStreams,
     3   add more checks for compression failure,
     4   fix output for zero-length input (ticket #1915)
     5
     62017-02-10 zzz
     7 * Test: Add random delays and drops to LocalClientManager
     8
    192017-02-09 zzz
    2  * Streaming: Fix optional delay and choking (tickets #1046, 1939)
     10 * Streaming: Fix optional delay and choking (tickets #1046, #1939)
    311
    4122017-02-08 zzz
  • router/java/src/net/i2p/router/RouterVersion.java

    r17b781c1 rf2ae1bf  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 6;
     21    public final static long BUILD = 7;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.