mirror of
https://github.com/google/leveldb.git
synced 2025-04-25 14:00:27 +08:00
Merge ab065d80c0
into ac691084fd
This commit is contained in:
commit
5721fba947
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user