Player3324 · GitHub

Describe the bug
Opening some nps files containing CPU sampling snapshot data will fail with an "Opening snapshot failed." error dialog.

The way

snapshot.readFromStream(dataDis);

and surrounding code was implemented doesn't guarantee that the entire compressedDataLen bytes were read from dis.

If the alignment between the involved buffer and net data sizes happens to lie within the tailing zlib checksum bytes, this checksum won't ever be fully read or checked. The following settingsLen read will then start too early, including the last part of the zlib checksum in its value and thus corrupting itself and any remaining reads.

This should be easy to fix by doing another dataDis.read() after the above quoted line, which would then return -1 (EOF) and make sure the entire compressed data was pulled in.

To Reproduce
Unzip and try to load visualvm-bug.zip

Expected behavior
The nps file gets loaded without an error

Read the original on github.com ↗