1
0
mirror of https://github.com/google/leveldb.git synced 2025-04-25 14:00:27 +08:00
This commit is contained in:
Christopher Jeffrey (JJ) 2025-02-06 19:40:25 +08:00 committed by GitHub
commit 5721fba947
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 3 deletions

View File

@ -68,7 +68,8 @@ static inline const char* DecodeEntry(const char* p, const char* limit,
if ((p = GetVarint32Ptr(p, limit, value_length)) == nullptr) return nullptr;
}
if (static_cast<uint32_t>(limit - p) < (*non_shared + *value_length)) {
if (static_cast<uint64_t>(limit - p) <
(static_cast<uint64_t>(*non_shared) + *value_length)) {
return nullptr;
}
return p;

View File

@ -72,6 +72,11 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
result->cachable = false;
result->heap_allocated = false;
// Check for overflow.
if (handle.size() > std::numeric_limits<size_t>::max() - kBlockTrailerSize) {
return Status::Corruption("block handle size overflow");
}
// Read the block contents as well as the type/crc footer.
// See table_builder.cc for the code that built this structure.
size_t n = static_cast<size_t>(handle.size());

View File

@ -198,6 +198,10 @@ class PosixRandomAccessFile final : public RandomAccessFile {
Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override {
if (offset > std::numeric_limits<off_t>::max()) {
return PosixError(filename_, EINVAL);
}
int fd = fd_;
if (!has_permanent_fd_) {
fd = ::open(filename_.c_str(), O_RDONLY | kOpenBaseFlags);
@ -258,7 +262,7 @@ class PosixMmapReadableFile final : public RandomAccessFile {
Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override {
if (offset + n > length_) {
if (offset + n < n || offset + n > length_) {
*result = Slice();
return PosixError(filename_, EINVAL);
}

View File

@ -247,7 +247,7 @@ class WindowsMmapReadableFile : public RandomAccessFile {
Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const override {
if (offset + n > length_) {
if (offset + n < n || offset + n > length_) {
*result = Slice();
return WindowsError(filename_, ERROR_INVALID_PARAMETER);
}