Repository navigation
Description
What happens
CompressedBlockInputStream.refill throws EOFException("Unexpected end of stream") when a block's 25-byte header is complete but the stream ends before any body byte. If the block starts at a row boundary, AbstractBinaryFormatReader.readRecord treats that as the end of data (e instanceof EOFException && firstColumn). The read then ends cleanly with rows missing.
The chance of this is low. The stream has to end cleanly (read returns -1) exactly after a block header, at a row boundary. A dropped HTTP connection throws ConnectionClosedException instead, and that read fails with an error as it should. A stream cut inside a block's header or body also fails correctly ("Incomplete read").
Version: client-v2 0.11.1.
Repro
One Int32 column, 50 rows, LZ4 blocks of 49 bytes, so block 1 holds the header and rows 0-9 exactly.
ByteArrayOutputStream plain = new ByteArrayOutputStream();
plain.write(new byte[] {1, 1, 'x', 5, 'I', 'n', 't', '3', '2'});
for (int i = 0; i < 50; i++) plain.write(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(i).array());
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream lz4 = new CompressedBlockOutputStream.LZ4OutputStream(out, LZ4Factory.fastestJavaInstance().fastCompressor(), 49);
lz4.write(plain.toByteArray());
lz4.close();
byte[] compressed = out.toByteArray();
int block1 = 16 + ByteBuffer.wrap(compressed, 17, 4).order(ByteOrder.LITTLE_ENDIAN).getInt();
QuerySettings settings = new QuerySettings();
settings.setOption(ClientConfigProperties.USE_SERVER_TIMEZONE.getKey(), Boolean.FALSE);
settings.setOption(ClientConfigProperties.USE_TIMEZONE.getKey(), TimeZone.getTimeZone("UTC"));
InputStream in = new CompressedBlockInputStream(
new ByteArrayInputStream(Arrays.copyOf(compressed, block1 + 25)), // block 2's header, no body
LZ4Factory.fastestJavaInstance().fastDecompressor(), 64 * 1024);
RowBinaryWithNamesAndTypesFormatReader reader =
new RowBinaryWithNamesAndTypesFormatReader(in, settings, new BinaryStreamReader.DefaultByteBufferAllocator());
int rows = 0;
while (reader.hasNext()) { reader.next(); rows++; }
System.out.println(rows); // 10, no exception| Stream cut | Result |
|---|---|
| not cut | 50 rows |
| inside block 2's header | IOException: Incomplete read: 10 of 25 |
| inside block 2's body | IOException: Incomplete read: 5 of 51 |
| right after block 2's header | 10 rows, no error |
Suggested fix
- In
refill, throw a plainIOException(orClientException) for a block whose body is missing, as a partly read body already does. - Related: when
read(b, off, len)spans several blocks and a laterrefillthrows, the bytes already copied from earlier blocks are lost. Returning them and throwing on the next call (asBufferedInputStreamdoes) would let callers that read in large chunks fail at the same position as callers that read in small ones.
Activity
polyglotAI-bot commentedon Nov 26, 2026
Recommendation: Keep open — fix needed
Review PR #3322: with its diff, the issue's steps fail with
DataTransferException: Unexpected end of streamin place of a clean end after 10 rows. The PR does not link this issue, and its diff has a merge conflict withmaininClientConfigProperties.java.main: Reproduced on main — the issue's steps print10with no error, as the issue shows (mainat8480ca001; the steps need no server).IOException. PR Improve compression handling #3322 also changes the other compressed-read errors toDataTransferException, which its own summary calls breaking.Analysis: Confirmed:
refillthrows theEOFExceptionfor an empty block body (CompressedBlockInputStream.java:136-138), andreadRecordtakes anEOFExceptionat the first column as the end of the data (AbstractBinaryFormatReader.java:202-205). The second point of the issue (readdrops the bytes of earlier blocks when a laterrefillthrows,CompressedBlockInputStream.java:59-63) changes only where the read fails, not whether it fails.Automated triage by Polyglot AI. A maintainer makes the final decision.