Simplification

pull/217/head
M66B 9 months ago
parent e277be5d63
commit 8097b268a3

@ -3863,24 +3863,36 @@ public class Helper {
@Override @Override
public int read() throws IOException { public int read() throws IOException {
int b = super.read(); int b = super.read();
if (b >= 0 && ++count > max) if (b >= 0) {
throw new IOException("Stream larger than " + max + " bytes"); count++;
checkLength();
}
return b; return b;
} }
@Override @Override
public int read(byte[] b) throws IOException { public int read(byte[] b) throws IOException {
for (int i = 0; i < b.length; i++) { int read = super.read(b);
b[i] = (byte) read(); if (read > 0) {
if (b[i] < 0) count += read;
return i; checkLength();
} }
return b.length; return read;
} }
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IOException {
throw new UnsupportedOperationException(); int read = super.read(b, off, len);
if (read > 0) {
count += read;
checkLength();
}
return read;
}
private void checkLength() throws IOException {
if (count > max)
throw new IOException("Stream larger than " + max + " bytes");
} }
} }
} }

@ -311,7 +311,7 @@ class ImageHelper {
svg.renderToCanvas(canvas); svg.renderToCanvas(canvas);
return bm; return bm;
} catch (Throwable ex) { } catch (Throwable ex) {
throw new IOException("SVG, ex"); throw new IOException("SVG, ex", ex);
} }
} }

Loading…
Cancel
Save