Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.function.Predicate;

import static org.elasticsearch.index.store.checksum.ChecksumBlobContainerIndexInput.checksumToBytesArray;
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsUtils.toIntBytes;

public abstract class BaseSearchableSnapshotIndexInput extends BufferedIndexInput {

Expand Down Expand Up @@ -99,16 +100,21 @@ private boolean maybeReadChecksumFromFileInfo(ByteBuffer b) throws IOException {
return false;
}
final long position = getFilePointer() + this.offset;
if (position < fileInfo.length() - CodecUtil.footerLength()) {
final long checksumPosition = fileInfo.length() - CodecUtil.footerLength();
if (position < checksumPosition) {
return false;
}
if (isClone) {
return false;
}
boolean success = false;
try {
final int checksumOffset = toIntBytes(Math.subtractExact(position, checksumPosition));
assert checksumOffset <= CodecUtil.footerLength() : checksumOffset;
assert 0 <= checksumOffset : checksumOffset;

final byte[] checksum = checksumToBytesArray(fileInfo.checksum());
b.put(checksum, CodecUtil.footerLength() - remaining, remaining);
b.put(checksum, checksumOffset, remaining);
success = true;
} catch (NumberFormatException e) {
// tests disable this optimisation by passing an invalid checksum
Expand Down