Changeset 5a715f3


Ignore:
Timestamp:
Dec 13, 2011 3:57:51 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
69e5760b
Parents:
f9818a2b
Message:
  • ResettableGZIPInputStream: Better footer log errors
File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/ResettableGZIPInputStream.java

    rf9818a2b r5a715f3  
    88import java.util.zip.Inflater;
    99import java.util.zip.InflaterInputStream;
     10
     11import net.i2p.data.DataHelper;
    1012
    1113/**
     
    185187        byte footer[] = _lookaheadStream.getFooter();
    186188       
    187         long expectedCRCVal = _crc32.getValue();
    188        
    189         // damn RFC writing their bytes backwards...
    190         if (!(footer[0] == (byte)(expectedCRCVal & 0xFF)))
    191             throw new IOException("footer[0]=" + footer[0] + " expectedCRC[0]="
    192                                   + (expectedCRCVal & 0xFF));
    193         if (!(footer[1] == (byte)(expectedCRCVal >>> 8)))
    194             throw new IOException("footer[1]=" + footer[1] + " expectedCRC[1]="
    195                                   + ((expectedCRCVal >>> 8) & 0xFF));
    196         if (!(footer[2] == (byte)(expectedCRCVal >>> 16)))
    197             throw new IOException("footer[2]=" + footer[2] + " expectedCRC[2]="
    198                                   + ((expectedCRCVal >>> 16) & 0xFF));
    199         if (!(footer[3] == (byte)(expectedCRCVal >>> 24)))
    200             throw new IOException("footer[3]=" + footer[3] + " expectedCRC[3]="
    201                                   + ((expectedCRCVal >>> 24) & 0xFF));
    202        
    203         int expectedSizeVal = inf.getTotalOut();
    204        
    205         if (!(footer[4] == (byte)expectedSizeVal))
    206             throw new IOException("footer[4]=" + footer[4] + " expectedSize[0]="
    207                                   + (expectedSizeVal & 0xFF));
    208         if (!(footer[5] == (byte)(expectedSizeVal >>> 8)))
    209             throw new IOException("footer[5]=" + footer[5] + " expectedSize[1]="
    210                                   + ((expectedSizeVal >>> 8) & 0xFF));
    211         if (!(footer[6] == (byte)(expectedSizeVal >>> 16)))
    212             throw new IOException("footer[6]=" + footer[6] + " expectedSize[2]="
    213                                   + ((expectedSizeVal >>> 16) & 0xFF));
    214         if (!(footer[7] == (byte)(expectedSizeVal >>> 24)))
    215             throw new IOException("footer[7]=" + footer[7] + " expectedSize[3]="
    216                                   + ((expectedSizeVal >>> 24) & 0xFF));
     189        long actualSize = inf.getTotalOut();
     190        long expectedSize = DataHelper.fromLongLE(footer, 4, 4);
     191        if (expectedSize != actualSize)
     192            throw new IOException("gunzip expected " + expectedSize + " bytes, got " + actualSize);
     193       
     194        long actualCRC = _crc32.getValue();
     195        long expectedCRC = DataHelper.fromLongLE(footer, 0, 4);
     196        if (expectedCRC != actualCRC)
     197            throw new IOException("gunzip CRC fail expected 0x" + Long.toHexString(expectedCRC) +
     198                                  " bytes, got 0x" + Long.toHexString(actualCRC));
    217199    }
    218200   
Note: See TracChangeset for help on using the changeset viewer.