File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 2424import java .util .function .Predicate ;
2525
2626import static org .elasticsearch .index .store .checksum .ChecksumBlobContainerIndexInput .checksumToBytesArray ;
27+ import static org .elasticsearch .xpack .searchablesnapshots .SearchableSnapshotsUtils .toIntBytes ;
2728
2829public abstract class BaseSearchableSnapshotIndexInput extends BufferedIndexInput {
2930
@@ -99,16 +100,21 @@ private boolean maybeReadChecksumFromFileInfo(ByteBuffer b) throws IOException {
99100 return false ;
100101 }
101102 final long position = getFilePointer () + this .offset ;
102- if (position < fileInfo .length () - CodecUtil .footerLength ()) {
103+ final long checksumPosition = fileInfo .length () - CodecUtil .footerLength ();
104+ if (position < checksumPosition ) {
103105 return false ;
104106 }
105107 if (isClone ) {
106108 return false ;
107109 }
108110 boolean success = false ;
109111 try {
112+ final int checksumOffset = toIntBytes (Math .subtractExact (position , checksumPosition ));
113+ assert checksumOffset <= CodecUtil .footerLength () : checksumOffset ;
114+ assert 0 <= checksumOffset : checksumOffset ;
115+
110116 final byte [] checksum = checksumToBytesArray (fileInfo .checksum ());
111- b .put (checksum , CodecUtil . footerLength () - remaining , remaining );
117+ b .put (checksum , checksumOffset , remaining );
112118 success = true ;
113119 } catch (NumberFormatException e ) {
114120 // tests disable this optimisation by passing an invalid checksum
You can’t perform that action at this time.
0 commit comments