Skip to content

Commit 01e0497

Browse files
committed
Adds hex dump length safety check
1 parent 04d121f commit 01e0497

File tree

3 files changed

+5
-18
lines changed

3 files changed

+5
-18
lines changed

mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,8 @@ public String getHexDump(int length) {
15451545
* @return hexidecimal representation of this buffer
15461546
*/
15471547
public String getHexDump(int length, boolean pretty) {
1548-
return (pretty) ? IoBufferHexDumper.getPrettyHexDumpSlice(this, this.position(), length)
1549-
: IoBufferHexDumper.getHexDumpSlice(this, this.position(), length);
1548+
return (pretty) ? IoBufferHexDumper.getPrettyHexDumpSlice(this, this.position(), Math.min(this.remaining(), length))
1549+
: IoBufferHexDumper.getHexDumpSlice(this, this.position(), Math.min(this.remaining(), length));
15501550
}
15511551

15521552
// //////////////////////////////

mina-core/src/main/java/org/apache/mina/core/buffer/IoBufferHexDumper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.mina.core.buffer;
2121

2222
import java.io.UnsupportedEncodingException;
23-
import java.nio.charset.StandardCharsets;
2423

2524
/**
2625
* Provides utility methods to dump an {@link IoBuffer} into a hex formatted

mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferHexDumperTest.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ public void checkHexDumpLength() {
1616

1717
buf.flip();
1818

19-
// System.out.println(buf.getHexDump());
20-
// System.out.println(buf.getHexDump(20));
21-
// System.out.println(buf.getHexDump(50));
22-
2319
/* special case */
2420
assertEquals(0, buf.getHexDump(0).length());
2521

@@ -28,9 +24,9 @@ public void checkHexDumpLength() {
2824
assertEquals((Math.min(300, buf.limit()) * 3) - 1, buf.getHexDump(300).length());
2925

3026
/* must truncate */
31-
assertEquals((7 * 3) + 2, buf.getHexDump(7).length());
32-
assertEquals((10 * 3) + 2, buf.getHexDump(10).length());
33-
assertEquals((30 * 3) + 2, buf.getHexDump(30).length());
27+
assertEquals((7 * 3) - 1, buf.getHexDump(7).length());
28+
assertEquals((10 * 3) - 1, buf.getHexDump(10).length());
29+
assertEquals((30 * 3) - 1, buf.getHexDump(30).length());
3430

3531
}
3632

@@ -44,15 +40,7 @@ public void checkPrettyHexDumpLength() {
4440

4541
buf.flip();
4642

47-
// System.out.println(buf.getHexDump(0, true));
48-
// System.out.println(buf.getHexDump(20, true));
49-
// System.out.println(buf.getHexDump(50, true));
50-
5143
String[] dump = buf.getHexDump(50, true).split("\\n");
52-
53-
for (String x : dump) {
54-
System.out.println(x);
55-
}
5644

5745
assertEquals(4, dump.length);
5846
}

0 commit comments

Comments
 (0)