Skip to content

Commit 2c61efe

Browse files
committed
8282648: Weaken the InflaterInputStream specification in order to allow faster Zip implementations
Reviewed-by: lancea, alanb, jpai, mr, darcy
1 parent e31c537 commit 2c61efe

File tree

7 files changed

+82
-19
lines changed

7 files changed

+82
-19
lines changed

src/java.base/share/classes/java/net/URLConnection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,12 @@ public Permission getPermission() throws IOException {
840840
* returned input stream if the read timeout expires before data
841841
* is available for read.
842842
*
843+
* @apiNote The {@code InputStream} returned by this method can wrap an
844+
* {@link java.util.zip.InflaterInputStream InflaterInputStream}, whose
845+
* {@link java.util.zip.InflaterInputStream#read(byte[], int, int)
846+
* read(byte[], int, int)} method can modify any element of the output
847+
* buffer.
848+
*
843849
* @return an input stream that reads from this open connection.
844850
* @throws IOException if an I/O error occurs while
845851
* creating the input stream.

src/java.base/share/classes/java/util/jar/JarFile.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,13 @@ private byte[] getBytes(ZipEntry ze) throws IOException {
822822
/**
823823
* Returns an input stream for reading the contents of the specified
824824
* zip file entry.
825+
*
826+
* @apiNote The {@code InputStream} returned by this method can wrap an
827+
* {@link java.util.zip.InflaterInputStream InflaterInputStream}, whose
828+
* {@link java.util.zip.InflaterInputStream#read(byte[], int, int)
829+
* read(byte[], int, int)} method can modify any element of the output
830+
* buffer.
831+
*
825832
* @param ze the zip file entry
826833
* @return an input stream for reading the contents of the specified
827834
* zip file entry or null if the zip file entry does not exist

src/java.base/share/classes/java/util/jar/JarInputStream.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,21 @@ public JarEntry getNextJarEntry() throws IOException {
167167
}
168168

169169
/**
170-
* Reads from the current JAR file entry into an array of bytes.
171-
* If {@code len} is not zero, the method
172-
* blocks until some input is available; otherwise, no
173-
* bytes are read and {@code 0} is returned.
170+
* Reads from the current JAR entry into an array of bytes, returning the number of
171+
* inflated bytes. If {@code len} is not zero, the method blocks until some input is
172+
* available; otherwise, no bytes are read and {@code 0} is returned.
173+
* <p>
174+
* If the current entry is compressed and this method returns a nonzero
175+
* integer <i>n</i> then {@code buf[off]}
176+
* through {@code buf[off+}<i>n</i>{@code -1]} contain the uncompressed
177+
* data. The content of elements {@code buf[off+}<i>n</i>{@code ]} through
178+
* {@code buf[off+}<i>len</i>{@code -1]} is undefined, contrary to the
179+
* specification of the {@link java.io.InputStream InputStream} superclass,
180+
* so an implementation is free to modify these elements during the inflate
181+
* operation. If this method returns {@code -1} or throws an exception then
182+
* the content of {@code buf[off]} through {@code buf[off+}<i>len</i>{@code
183+
* -1]} is undefined.
184+
* <p>
174185
* If verification has been enabled, any invalid signature
175186
* on the current entry will be reported at some point before the
176187
* end of the entry is reached.

src/java.base/share/classes/java/util/zip/GZIPInputStream.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -92,13 +92,24 @@ public GZIPInputStream(InputStream in) throws IOException {
9292
}
9393

9494
/**
95-
* Reads uncompressed data into an array of bytes. If {@code len} is not
96-
* zero, the method will block until some input can be decompressed; otherwise,
97-
* no bytes are read and {@code 0} is returned.
95+
* Reads uncompressed data into an array of bytes, returning the number of inflated
96+
* bytes. If {@code len} is not zero, the method will block until some input can be
97+
* decompressed; otherwise, no bytes are read and {@code 0} is returned.
98+
* <p>
99+
* If this method returns a nonzero integer <i>n</i> then {@code buf[off]}
100+
* through {@code buf[off+}<i>n</i>{@code -1]} contain the uncompressed
101+
* data. The content of elements {@code buf[off+}<i>n</i>{@code ]} through
102+
* {@code buf[off+}<i>len</i>{@code -1]} is undefined, contrary to the
103+
* specification of the {@link java.io.InputStream InputStream} superclass,
104+
* so an implementation is free to modify these elements during the inflate
105+
* operation. If this method returns {@code -1} or throws an exception then
106+
* the content of {@code buf[off]} through {@code buf[off+}<i>len</i>{@code
107+
* -1]} is undefined.
108+
*
98109
* @param buf the buffer into which the data is read
99-
* @param off the start offset in the destination array {@code b}
110+
* @param off the start offset in the destination array {@code buf}
100111
* @param len the maximum number of bytes read
101-
* @return the actual number of bytes read, or -1 if the end of the
112+
* @return the actual number of bytes inflated, or -1 if the end of the
102113
* compressed input stream is reached
103114
*
104115
* @throws NullPointerException If {@code buf} is {@code null}.

src/java.base/share/classes/java/util/zip/InflaterInputStream.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,24 @@ public int read() throws IOException {
124124
}
125125

126126
/**
127-
* Reads uncompressed data into an array of bytes. If {@code len} is not
128-
* zero, the method will block until some input can be decompressed; otherwise,
129-
* no bytes are read and {@code 0} is returned.
127+
* Reads uncompressed data into an array of bytes, returning the number of inflated
128+
* bytes. If {@code len} is not zero, the method will block until some input can be
129+
* decompressed; otherwise, no bytes are read and {@code 0} is returned.
130+
* <p>
131+
* If this method returns a nonzero integer <i>n</i> then {@code buf[off]}
132+
* through {@code buf[off+}<i>n</i>{@code -1]} contain the uncompressed
133+
* data. The content of elements {@code buf[off+}<i>n</i>{@code ]} through
134+
* {@code buf[off+}<i>len</i>{@code -1]} is undefined, contrary to the
135+
* specification of the {@link java.io.InputStream InputStream} superclass,
136+
* so an implementation is free to modify these elements during the inflate
137+
* operation. If this method returns {@code -1} or throws an exception then
138+
* the content of {@code buf[off]} through {@code buf[off+}<i>len</i>{@code
139+
* -1]} is undefined.
140+
*
130141
* @param b the buffer into which the data is read
131142
* @param off the start offset in the destination array {@code b}
132143
* @param len the maximum number of bytes read
133-
* @return the actual number of bytes read, or -1 if the end of the
144+
* @return the actual number of bytes inflated, or -1 if the end of the
134145
* compressed input is reached or a preset dictionary is needed
135146
* @throws NullPointerException If {@code b} is {@code null}.
136147
* @throws IndexOutOfBoundsException If {@code off} is negative,

src/java.base/share/classes/java/util/zip/ZipFile.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ public ZipEntry getEntry(String name) {
343343
* Closing this ZIP file will, in turn, close all input streams that
344344
* have been returned by invocations of this method.
345345
*
346+
* @apiNote The {@code InputStream} returned by this method can wrap an
347+
* {@link java.util.zip.InflaterInputStream InflaterInputStream}, whose
348+
* {@link java.util.zip.InflaterInputStream#read(byte[], int, int)
349+
* read(byte[], int, int)} method can modify any element of the output
350+
* buffer.
351+
*
346352
* @param entry the zip file entry
347353
* @return the input stream for reading the contents of the specified
348354
* zip file entry or null if the zip file entry does not exist

src/java.base/share/classes/java/util/zip/ZipInputStream.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -165,10 +165,21 @@ public int available() throws IOException {
165165
}
166166

167167
/**
168-
* Reads from the current ZIP entry into an array of bytes.
169-
* If {@code len} is not zero, the method
170-
* blocks until some input is available; otherwise, no
171-
* bytes are read and {@code 0} is returned.
168+
* Reads from the current ZIP entry into an array of bytes, returning the number of
169+
* inflated bytes. If {@code len} is not zero, the method blocks until some input is
170+
* available; otherwise, no bytes are read and {@code 0} is returned.
171+
* <p>
172+
* If the current entry is compressed and this method returns a nonzero
173+
* integer <i>n</i> then {@code buf[off]}
174+
* through {@code buf[off+}<i>n</i>{@code -1]} contain the uncompressed
175+
* data. The content of elements {@code buf[off+}<i>n</i>{@code ]} through
176+
* {@code buf[off+}<i>len</i>{@code -1]} is undefined, contrary to the
177+
* specification of the {@link java.io.InputStream InputStream} superclass,
178+
* so an implementation is free to modify these elements during the inflate
179+
* operation. If this method returns {@code -1} or throws an exception then
180+
* the content of {@code buf[off]} through {@code buf[off+}<i>len</i>{@code
181+
* -1]} is undefined.
182+
*
172183
* @param b the buffer into which the data is read
173184
* @param off the start offset in the destination array {@code b}
174185
* @param len the maximum number of bytes read

0 commit comments

Comments
 (0)