chamikaramj commented on a change in pull request #13513:
URL: https://github.com/apache/beam/pull/13513#discussion_r544791259
##########
File path:
sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlSource.java
##########
@@ -281,7 +283,15 @@ private long getFirstOccurenceOfRecordElement(
break outer;
} else {
// Matching was unsuccessful. Reset the buffer to include bytes
read for the char.
- ByteBuffer newbuf = ByteBuffer.allocate(BUF_SIZE);
+ int bytesToWrite = buf.remaining() + charBytes.length;
+ ByteBuffer newbuf;
+ if (bytesToWrite > BUF_SIZE) {
+ // Avoiding buffer overflow
Review comment:
Probably expand comment to following.
"The number of bytes to push to the buffer might be larger than BUF_SIZE due
to additional 'charBytes'."
##########
File path:
sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlSource.java
##########
@@ -320,7 +330,12 @@ private long getFirstOccurenceOfRecordElement(
recordStartBytesMatched = true;
}
}
- buf.clear();
+ if (bufSizeChanged) {
+ buf = ByteBuffer.allocate(BUF_SIZE);
Review comment:
Add a comment.
"We have to reset the size of the buffer to 'BUF_SIZE' to prevent it from
infinitely increasing."
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]