You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2016/11/29 19:50:49 UTC
olingo-odata2 git commit: [OLINGO-1053] Fixed buffer overflow
Repository: olingo-odata2
Updated Branches:
refs/heads/master dfe17829f -> de4aec1bd
[OLINGO-1053] Fixed buffer overflow
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/de4aec1b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/de4aec1b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/de4aec1b
Branch: refs/heads/master
Commit: de4aec1bd8183ecfff23297909eb5648885af388
Parents: dfe1782
Author: mibo <mi...@apache.org>
Authored: Tue Nov 29 20:49:09 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Tue Nov 29 20:50:21 2016 +0100
----------------------------------------------------------------------
.../odata2/core/batch/v2/BatchLineReader.java | 18 ++++++++++++------
.../odata2/core/batch/v2/BatchLineReaderTest.java | 18 ++++++++++++++++++
2 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/de4aec1b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
index 81cde03..4075764 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
@@ -151,12 +151,7 @@ public class BatchLineReader {
if (!foundLineEnd) {
byte currentChar = this.buffer[offset++];
- if(!buffer.hasRemaining()) {
- buffer.flip();
- ByteBuffer tmp = ByteBuffer.allocate(buffer.limit() *2);
- tmp.put(buffer);
- buffer = tmp;
- }
+ buffer = grantBuffer(buffer);
buffer.put(currentChar);
if (currentChar == LF) {
@@ -172,6 +167,7 @@ public class BatchLineReader {
// Check if there is at least one character
if (limit != EOF && this.buffer[offset] == LF) {
+ buffer = grantBuffer(buffer);
buffer.put(LF);
offset++;
}
@@ -193,6 +189,16 @@ public class BatchLineReader {
}
}
+ private ByteBuffer grantBuffer(ByteBuffer buffer) {
+ if(!buffer.hasRemaining()) {
+ buffer.flip();
+ ByteBuffer tmp = ByteBuffer.allocate(buffer.limit() *2);
+ tmp.put(buffer);
+ buffer = tmp;
+ }
+ return buffer;
+ }
+
private int fillBuffer() throws IOException {
limit = reader.read(buffer, 0, buffer.length);
offset = 0;
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/de4aec1b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java
index a734dd1..351c693 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java
@@ -27,6 +27,7 @@ import java.util.List;
import org.apache.olingo.odata2.core.batch.v2.BatchLineReader;
import org.apache.olingo.odata2.core.batch.v2.Line;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.junit.Test;
public class BatchLineReaderTest {
@@ -104,6 +105,23 @@ public class BatchLineReaderTest {
reader.close();
}
+ /**
+ * Test for special case (described in https://issues.apache.org/jira/browse/OLINGO-1053 )
+ */
+ @Test
+ public void testSpecialCRLF() throws IOException {
+ String line1 = StringHelper.generateData(8191);
+ String line2 = StringHelper.generateData(8192);
+ final String content = line1 + "\r\n" + line2 + "\n" + "test";
+
+ BatchLineReader reader = create(content);
+
+ assertEquals(line1 + "\r\n", reader.readLine());
+ assertEquals(line2 + "\n", reader.readLine());
+ assertEquals("test", reader.readLine());
+ reader.close();
+ }
+
@Test
public void testCR() throws IOException {
final String TEXT = "Test\r" +