提交 a3e83ab9 编写于 作者: S sherman

4263582: RFE: GZIPInputStream throws IOException on non-gzipped data

Summary: throw ZipException instead of IOException
Reviewed-by: martin
上级 ae4c8691
...@@ -66,6 +66,9 @@ class GZIPInputStream extends InflaterInputStream { ...@@ -66,6 +66,9 @@ class GZIPInputStream extends InflaterInputStream {
* Creates a new input stream with the specified buffer size. * Creates a new input stream with the specified buffer size.
* @param in the input stream * @param in the input stream
* @param size the input buffer size * @param size the input buffer size
*
* @exception ZipException if a GZIP format error has occurred or the
* compression method used is unsupported
* @exception IOException if an I/O error has occurred * @exception IOException if an I/O error has occurred
* @exception IllegalArgumentException if size is <= 0 * @exception IllegalArgumentException if size is <= 0
*/ */
...@@ -79,6 +82,9 @@ class GZIPInputStream extends InflaterInputStream { ...@@ -79,6 +82,9 @@ class GZIPInputStream extends InflaterInputStream {
/** /**
* Creates a new input stream with a default buffer size. * Creates a new input stream with a default buffer size.
* @param in the input stream * @param in the input stream
*
* @exception ZipException if a GZIP format error has occurred or the
* compression method used is unsupported
* @exception IOException if an I/O error has occurred * @exception IOException if an I/O error has occurred
*/ */
public GZIPInputStream(InputStream in) throws IOException { public GZIPInputStream(InputStream in) throws IOException {
...@@ -94,12 +100,14 @@ class GZIPInputStream extends InflaterInputStream { ...@@ -94,12 +100,14 @@ class GZIPInputStream extends InflaterInputStream {
* @param len the maximum number of bytes read * @param len the maximum number of bytes read
* @return the actual number of bytes read, or -1 if the end of the * @return the actual number of bytes read, or -1 if the end of the
* compressed input stream is reached * compressed input stream is reached
*
* @exception NullPointerException If <code>buf</code> is <code>null</code>. * @exception NullPointerException If <code>buf</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative, * @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than * <code>len</code> is negative, or <code>len</code> is greater than
* <code>buf.length - off</code> * <code>buf.length - off</code>
* @exception IOException if an I/O error has occurred or the compressed * @exception ZipException if the compressed input data is corrupt.
* input data is corrupt * @exception IOException if an I/O error has occurred.
*
*/ */
public int read(byte[] buf, int off, int len) throws IOException { public int read(byte[] buf, int off, int len) throws IOException {
ensureOpen(); ensureOpen();
...@@ -151,11 +159,11 @@ class GZIPInputStream extends InflaterInputStream { ...@@ -151,11 +159,11 @@ class GZIPInputStream extends InflaterInputStream {
crc.reset(); crc.reset();
// Check header magic // Check header magic
if (readUShort(in) != GZIP_MAGIC) { if (readUShort(in) != GZIP_MAGIC) {
throw new IOException("Not in GZIP format"); throw new ZipException("Not in GZIP format");
} }
// Check compression method // Check compression method
if (readUByte(in) != 8) { if (readUByte(in) != 8) {
throw new IOException("Unsupported compression method"); throw new ZipException("Unsupported compression method");
} }
// Read flags // Read flags
int flg = readUByte(in); int flg = readUByte(in);
...@@ -177,7 +185,7 @@ class GZIPInputStream extends InflaterInputStream { ...@@ -177,7 +185,7 @@ class GZIPInputStream extends InflaterInputStream {
if ((flg & FHCRC) == FHCRC) { if ((flg & FHCRC) == FHCRC) {
int v = (int)crc.getValue() & 0xffff; int v = (int)crc.getValue() & 0xffff;
if (readUShort(in) != v) { if (readUShort(in) != v) {
throw new IOException("Corrupt GZIP header"); throw new ZipException("Corrupt GZIP header");
} }
} }
} }
...@@ -196,7 +204,7 @@ class GZIPInputStream extends InflaterInputStream { ...@@ -196,7 +204,7 @@ class GZIPInputStream extends InflaterInputStream {
if ((readUInt(in) != crc.getValue()) || if ((readUInt(in) != crc.getValue()) ||
// rfc1952; ISIZE is the input size modulo 2^32 // rfc1952; ISIZE is the input size modulo 2^32
(readUInt(in) != (inf.getBytesWritten() & 0xffffffffL))) (readUInt(in) != (inf.getBytesWritten() & 0xffffffffL)))
throw new IOException("Corrupt GZIP trailer"); throw new ZipException("Corrupt GZIP trailer");
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册