From 524211fd8c358b7f5e0689aac18548e248a82fc3 Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Thu, 10 Oct 2024 10:45:28 -0700 Subject: [PATCH] Fix handling of end of user records Summary: This addresses some broken logic that didn't need to exist. For all files, if the index record is before user records, or after, and we can always trust that it if after, then it marks the end of user records data. Reviewed By: hanghu Differential Revision: D64150620 fbshipit-source-id: 61b40ed6e5b72fc538b6eccf9a84ade23c3dfd8e --- vrs/FileFormat.cpp | 17 +++-------------- vrs/RecordFileReader.cpp | 6 ++---- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/vrs/FileFormat.cpp b/vrs/FileFormat.cpp index 677a2b26..2a7a2718 100644 --- a/vrs/FileFormat.cpp +++ b/vrs/FileFormat.cpp @@ -111,20 +111,9 @@ void FileHeader::enableFrontIndexRecordSupport() { int64_t FileHeader::getEndOfUserRecordsOffset(int64_t fileSize) const { if (looksLikeAVRSFile()) { - switch (fileFormatVersion.get()) { - case kOriginalFileFormatVersion: - // index record always in the back, firstUserRecordOffset is 0 - if (indexRecordOffset.get() > 0) { - return min(fileSize, indexRecordOffset.get()); - } - break; - case kFrontIndexFileFormatVersion: - case kZstdFormatVersion: - // index maybe before or after the user records, and firstUserRecordOffset should be valid. - if (indexRecordOffset.get() > 0 && indexRecordOffset.get() > firstUserRecordOffset.get()) { - return min(fileSize, indexRecordOffset.get()); - } - break; + // index maybe before or after the user records + if (indexRecordOffset.get() > firstUserRecordOffset.get()) { + return min(fileSize, indexRecordOffset.get()); } } return fileSize; diff --git a/vrs/RecordFileReader.cpp b/vrs/RecordFileReader.cpp index 0c87f4a8..aec118f8 100644 --- a/vrs/RecordFileReader.cpp +++ b/vrs/RecordFileReader.cpp @@ -507,10 +507,8 @@ const vector& RecordFileReader::getRecordBoundaries() const { } lastOffset = r.fileOffset; } - int64_t fileSize = file_->getTotalSize(); - recordBoundaries_.emplace_back( - endOfUserRecordsOffset_ < fileSize ? endOfUserRecordsOffset_ : fileSize); - if (sortNeeded || recordBoundaries_.back() < lastOffset) { + recordBoundaries_.emplace_back(endOfUserRecordsOffset_); + if (sortNeeded) { sort(recordBoundaries_.begin(), recordBoundaries_.end()); } }