Skip to content

Commit 1632a66

Browse files
committed
Empty stream double check.
1 parent a5b8604 commit 1632a66

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

flight/flight-core/src/main/java/org/apache/arrow/flight/ArrowMessage.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ private static ArrowMessage frame(BufferAllocator allocator, final InputStream s
287287
ArrowBuf body = null;
288288
ArrowBuf appMetadata = null;
289289
while (stream.available() > 0) {
290-
int tag = readRawVarint32(stream);
290+
final int tagFirstByte = stream.read();
291+
if (tagFirstByte == -1) {
292+
break;
293+
}
294+
int tag = readRawVarint32(tagFirstByte, stream);
291295
switch (tag) {
292296
case DESCRIPTOR_TAG:
293297
{
@@ -366,6 +370,10 @@ private static ArrowMessage frame(BufferAllocator allocator, final InputStream s
366370

367371
private static int readRawVarint32(InputStream is) throws IOException {
368372
int firstByte = is.read();
373+
return readRawVarint32(firstByte, is);
374+
}
375+
376+
private static int readRawVarint32(int firstByte, InputStream is) throws IOException {
369377
return CodedInputStream.readRawVarint32(firstByte, is);
370378
}
371379

0 commit comments

Comments
 (0)