SusiMail: Prevent infinite loop on decoding error

More test mods
Fix StringBuilderWriter.write(int)
This commit is contained in:
zzz
2021-04-24 19:37:18 -04:00
parent 0a24e56ded
commit 21485eff87
4 changed files with 22 additions and 9 deletions

View File

@ -85,10 +85,17 @@ public class DecodingOutputStream extends OutputStream {
// So just check if we got a character back in the buffer.
if (result == null || (result.isError() && !_cb.hasRemaining())) {
_out.write(REPLACEMENT);
// need to do this or we will infinite loop
((Buffer)_bb).clear();
} else {
((Buffer)_cb).flip();
_out.append(_cb);
((Buffer)_cb).clear();
if (result.isError()) {
_out.write(REPLACEMENT);
// need to do this or we will infinite loop
((Buffer)_bb).clear();
}
}
}
@ -107,7 +114,7 @@ public class DecodingOutputStream extends OutputStream {
public static void main(String[] args) {
try {
String s = "Consider the encoding of the Euro sign, €." +
" The Unicode code point for \"€\" is U+20AC.";
" The Unicode code point for \"€\" is U+20AC.\n";
StringBuilder buf = new StringBuilder();
for (int i = 0; i < 100; i++) {
buf.append(s);
@ -118,10 +125,13 @@ public class DecodingOutputStream extends OutputStream {
Writer w = new StringBuilderWriter();
DecodingOutputStream r = new DecodingOutputStream(w, "UTF-8");
int b;
while ((b = bais.read()) >= 0) {
r.write(b);
byte[] bf = new byte[256];
int rand = 1 + net.i2p.I2PAppContext.getGlobalContext().random().nextInt(256);
while ((b = bais.read(bf, 0, rand)) >= 0) {
r.write(bf, 0, b);
rand = 1 + net.i2p.I2PAppContext.getGlobalContext().random().nextInt(256);
}
r.flush();
r.close();
System.out.println("Received: \"" + w.toString() + '"');
System.out.println("Test passed? " + w.toString().equals(s));
bais = new java.io.ByteArrayInputStream(new byte[] { 'x', (byte) 0xcc, 'x' } );
@ -130,7 +140,7 @@ public class DecodingOutputStream extends OutputStream {
while ((b = bais.read()) >= 0) {
r.write(b);
}
r.flush();
r.close();
System.out.println("Received: \"" + w.toString() + '"');
} catch (IOException ioe) {
ioe.printStackTrace();

View File

@ -47,7 +47,7 @@ public class StringBuilderWriter extends Writer {
@Override
public void write(int c) {
buf.append(c);
buf.append((char) c);
}
@Override

View File

@ -1,10 +1,13 @@
2021-04-24 zzz
* Jetty: Patch for CVE-2021-28165 Jetty #6072 -
Jetty server high CPU when client send data length > 17408
* SusiMail: Fix infinite loop in decoder on malformed input
2021-04-24 zlatinb
* SusiMail: Fix stream closed exception reading new mail
(trac ticket #2202, gitlab ticket #17)
* SusiMail:
- Fix stream closed exception reading new mail
(trac ticket #2202, gitlab ticket #17)
- Fix corruption of large messages (ticket #2765)
2021-04-23 idk
* Router: Fix update on Windows from very old versions (gitlab ticket #16)

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Git";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 14;
public final static long BUILD = 15;
/** for example "-test" */
public final static String EXTRA = "";