Skip to content

Commit

Permalink
Fix invalid magic number issue
Browse files Browse the repository at this point in the history
When we read the image data, we have to use readFully.  Otherwise, if
GRIP is in the middle of sending the image, we could end up reading half
of it and interpretting the next few bytes as the header of the next
image, resulting in an "incorrect magic number" error.

In practice, this seems to happen when GRIP is publishing large,
high-quality images or is running on a slower machine.
  • Loading branch information
ThomasJClark committed Feb 10, 2016
1 parent 2847a92 commit 752b1b9
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class GRIPExtension extends StaticWidget {
// then the raw bytes.
int imageSize = inputStream.readInt();
imageBuffer = growIfNecessary(imageBuffer, imageSize);
inputStream.read(imageBuffer, 0, imageSize);
inputStream.readFully(imageBuffer, 0, imageSize);

// Decode the image and redraw
gripImage.setImage(ImageIO.read(new ByteArrayInputStream(imageBuffer, 0, imageSize)));
Expand Down

0 comments on commit 752b1b9

Please sign in to comment.