Skip to content

Commit

Permalink
fix bug introduced in refactor when chunk.length >= maxCompressedLength
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwest committed Dec 27, 2024
1 parent 5311492 commit 1739afa
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/java/org/apache/cassandra/io/util/CompressedChunkReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,20 @@ public void readChunk(long position, ByteBuffer uncompressed)
}
else
{
uncompressed.put(reader.read(chunk, shouldCheckCrc));
uncompressed.position(0).limit(chunk.length);
if (channel.read(uncompressed, chunk.offset) != chunk.length)
throw new CorruptBlockException(channel.filePath(), chunk);

if (shouldCheckCrc)
{
uncompressed.flip();
int checksum = (int) ChecksumType.CRC32.of(uncompressed);

ByteBuffer scratch = ByteBuffer.allocate(Integer.BYTES);
if (channel.read(scratch, chunk.offset + chunk.length) != Integer.BYTES
|| scratch.getInt(0) != checksum)
throw new CorruptBlockException(channel.filePath(), chunk);
}
}
uncompressed.flip();
}
Expand Down

0 comments on commit 1739afa

Please sign in to comment.