Skip to content

Commit

Permalink
don't corrupt checksum of cfs file
Browse files Browse the repository at this point in the history
Closes #33881
  • Loading branch information
Vladimir Dolzhenko committed Sep 20, 2018
1 parent 76a1a86 commit 5f5874d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,19 @@ public static void corruptFile(Random random, Path... files) throws IOException
checksumBeforeCorruption = CodecUtil.retrieveChecksum(input);
}
try (FileChannel raf = FileChannel.open(fileToCorrupt, StandardOpenOption.READ, StandardOpenOption.WRITE)) {
long maxPosition = raf.size();

if (fileToCorrupt.getFileName().toString().endsWith(".cfs") && maxPosition > Integer.BYTES) {
// TODO: it is known that Lucene does not check the tail of CFS file (CompoundFileS, like an archive), see note at
// https://github.com/apache/lucene-solr/blob/branch_7_5/lucene/core/src/java/org/apache/lucene/codecs/lucene50/
// Lucene50CompoundReader.java#L82
// so far, don't corrupt checksum (last 4 bytes) of cfs file
maxPosition -= Integer.BYTES;
}
final int position = random.nextInt((int) Math.min(Integer.MAX_VALUE, maxPosition));

// read
raf.position(random.nextInt((int) Math.min(Integer.MAX_VALUE, raf.size())));
raf.position(position);
long filePointer = raf.position();
ByteBuffer bb = ByteBuffer.wrap(new byte[1]);
raf.read(bb);
Expand Down

0 comments on commit 5f5874d

Please sign in to comment.