diff --git a/src/de/mas/wiiu/jnus/utils/StreamUtils.java b/src/de/mas/wiiu/jnus/utils/StreamUtils.java index 115b43a..a5fa185 100644 --- a/src/de/mas/wiiu/jnus/utils/StreamUtils.java +++ b/src/de/mas/wiiu/jnus/utils/StreamUtils.java @@ -48,6 +48,7 @@ public final class StreamUtils { curReadChunk = toRead; } int read = in.read(buffer, 0, curReadChunk); + StreamUtils.checkForException(in); if (read < 0) break; System.arraycopy(buffer, 0, result, size - toRead, read); toRead -= read; @@ -65,6 +66,7 @@ public final class StreamUtils { do { try { bytesRead = inputStream.read(overflowbuf, overflowbuffer.getLengthOfDataInBuffer(), overflowbuffer.getSpaceLeft()); + StreamUtils.checkForException(inputStream); } catch (IOException e) { log.info(e.getMessage()); if (!e.getMessage().equals("Write end dead")) { @@ -141,6 +143,7 @@ public final class StreamUtils { long written = 0; do { read = inputStream.read(buffer); + StreamUtils.checkForException(inputStream); if (read < 0) { break; } @@ -192,4 +195,15 @@ public final class StreamUtils { } } + + public static void checkForException(InputStream inputStream) throws IOException { + if (inputStream instanceof PipedInputStreamWithException) { + try { + ((PipedInputStreamWithException) inputStream).checkForException(); + } catch (Exception e) { + throw new IOException(e); + } + } + } + } diff --git a/src/de/mas/wiiu/jnus/utils/cryptography/NUSDecryption.java b/src/de/mas/wiiu/jnus/utils/cryptography/NUSDecryption.java index 0883d0c..0754ad0 100644 --- a/src/de/mas/wiiu/jnus/utils/cryptography/NUSDecryption.java +++ b/src/de/mas/wiiu/jnus/utils/cryptography/NUSDecryption.java @@ -31,6 +31,7 @@ import de.mas.wiiu.jnus.entities.content.Content; import de.mas.wiiu.jnus.utils.ByteArrayBuffer; import de.mas.wiiu.jnus.utils.CheckSumWrongException; import de.mas.wiiu.jnus.utils.HashUtil; +import de.mas.wiiu.jnus.utils.PipedInputStreamWithException; import de.mas.wiiu.jnus.utils.StreamUtils; import de.mas.wiiu.jnus.utils.Utils; import lombok.extern.java.Log; @@ -101,7 +102,9 @@ public class NUSDecryption extends AESDecryption { int readTotal = 0; while (readTotal < toRead) { int res = inputStream.read(data, readTotal, toRead - readTotal); + StreamUtils.checkForException(inputStream); if (res < 0) { + // This should NEVER happen. throw new IOException(); } readTotal += res;