Skip to content

Commit 1060701

Browse files
committed
fixes #127 Possible ArrayIndexOutOfBoundsException in MigrationReader.
1 parent 3f46ed4 commit 1060701

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/org/apache/ibatis/migration/MigrationReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public int read(char[] cbuf, int off, int len) throws IOException {
124124
if (bufferLen == 0) {
125125
return -1;
126126
} else {
127-
return readFromBuffer(cbuf, off, bufferLen);
127+
return readFromBuffer(cbuf, off, len);
128128
}
129129
}
130130
break;

src/test/java/org/apache/ibatis/migration/MigrationReaderTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.InputStream;
2323
import java.io.Reader;
2424
import java.io.UnsupportedEncodingException;
25+
import java.util.Arrays;
2526
import java.util.Properties;
2627

2728
import org.junit.After;
@@ -305,6 +306,27 @@ public void shouldRespectSpecifiedOffsetAndLength() throws Exception {
305306
}
306307
}
307308

309+
@Test
310+
public void testReadWithBuffer() throws Exception {
311+
// @formatter:off
312+
String script = "long do part 123456789012345678901234567890\n"
313+
+ "--//@UNDO\n"
314+
+ "undo part\n";
315+
// @formatter:on
316+
MigrationReader reader = new MigrationReader(strToInputStream(script, charset), charset, false, null);
317+
try {
318+
StringBuilder buffer = new StringBuilder();
319+
char[] cbuf = new char[30];
320+
int res;
321+
while ((res = reader.read(cbuf)) != -1) {
322+
buffer.append(res == cbuf.length ? cbuf : Arrays.copyOf(cbuf, res));
323+
}
324+
assertEquals("long do part 123456789012345678901234567890\n", buffer.toString());
325+
} finally {
326+
reader.close();
327+
}
328+
}
329+
308330
private String readAsString(Reader reader) throws IOException {
309331
try {
310332
StringBuilder buffer = new StringBuilder();

0 commit comments

Comments
 (0)