RFR: 7036144: GZIPInputStream readTrailer uses faulty available() test for end-of-stream

Eirik Bjorsnos duke at openjdk.org
Thu Dec 14 21:17:38 UTC 2023


On Thu, 14 Dec 2023 20:15:39 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> `GZIPInputStream`, when looking for a concatenated stream, relies on what the underlying `InputStream` says is how many bytes are `available()`. But this is inappropriate because `InputStream.available()` is just an estimate and is allowed (for example) to always return zero.
> 
> The fix is to ignore what's `available()` and just proceed and see what happens. If fewer bytes are available than required, the attempt to extend to another stream is canceled just as it was before, e.g., when the next stream header couldn't be read.

test/jdk/java/util/zip/GZIP/GZIPInputStreamAvailable.java line 37:

> 35:     public static void main(String [] args) throws IOException {
> 36: 
> 37:         // Create gz data

Perhaps expand the comment to explain that you are creating a concatenated stream?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17113#discussion_r1427291799


More information about the core-libs-dev mailing list