From 752b1b94b7b4cc8ffab3176af7e0ae39839215fe Mon Sep 17 00:00:00 2001 From: Tom Clark Date: Wed, 10 Feb 2016 16:26:50 -0500 Subject: [PATCH] Fix invalid magic number issue 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. --- src/main/java/edu/wpi/grip/smartdashboard/GRIPExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/wpi/grip/smartdashboard/GRIPExtension.java b/src/main/java/edu/wpi/grip/smartdashboard/GRIPExtension.java index 11bffb6..faf400b 100644 --- a/src/main/java/edu/wpi/grip/smartdashboard/GRIPExtension.java +++ b/src/main/java/edu/wpi/grip/smartdashboard/GRIPExtension.java @@ -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)));