Skip to content

Commit

Permalink
validate checksum in footer separately for segment metadata files (#6931
Browse files Browse the repository at this point in the history
)

Signed-off-by: Varun Bansal <[email protected]>
  • Loading branch information
linuxpi authored Apr 4, 2023
1 parent c0a8cf8 commit 1856090
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.IOException;

import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.store.BufferedChecksumIndexInput;
import org.apache.lucene.store.ChecksumIndexInput;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
Expand Down Expand Up @@ -47,10 +46,9 @@ public VersionedCodecStreamWrapper(IndexIOStreamHandler<T> indexIOStreamHandler,
* @return stream content parsed into {@link T}
*/
public T readStream(IndexInput indexInput) throws IOException {
ChecksumIndexInput checksumIndexInput = new BufferedChecksumIndexInput(indexInput);
int readStreamVersion = checkHeader(checksumIndexInput);
T content = getHandlerForVersion(readStreamVersion).readContent(checksumIndexInput);
checkFooter(checksumIndexInput);
CodecUtil.checksumEntireFile(indexInput);
int readStreamVersion = checkHeader(indexInput);
T content = getHandlerForVersion(readStreamVersion).readContent(indexInput);
return content;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.opensearch.common.UUIDs;
import org.opensearch.common.lucene.store.ByteArrayIndexInput;
import org.opensearch.index.store.remote.metadata.RemoteSegmentMetadata;
import org.opensearch.common.io.VersionedCodecStreamWrapper;
import org.opensearch.index.store.remote.metadata.RemoteSegmentMetadataHandler;
Expand Down Expand Up @@ -135,7 +136,9 @@ private Map<String, UploadedSegmentMetadata> readLatestMetadataFile() throws IOE

private Map<String, UploadedSegmentMetadata> readMetadataFile(String metadataFilename) throws IOException {
try (IndexInput indexInput = remoteMetadataDirectory.openInput(metadataFilename, IOContext.DEFAULT)) {
RemoteSegmentMetadata metadata = metadataStreamWrapper.readStream(indexInput);
byte[] metadataBytes = new byte[(int) indexInput.length()];
indexInput.readBytes(metadataBytes, 0, (int) indexInput.length());
RemoteSegmentMetadata metadata = metadataStreamWrapper.readStream(new ByteArrayIndexInput(metadataFilename, metadataBytes));
return metadata.getMetadata();
}
}
Expand Down

0 comments on commit 1856090

Please sign in to comment.